1# Usage of ``ESObject`` type is restricted 2 3Rule ``arkts-limited-esobject`` 4 5**Severity: warning** 6 7ArkTS does not allow using ``ESObject`` type in some cases. The most part of limitations 8are put in place in order to prevent spread of dynamic objects in the static codebase. 9The only scenario where it is permited to use ``ESObject`` as type specifier is in local 10variable declaration. Initialization of variables with ``ESObject`` type is also limited. 11Such variables can only be initialized with values that originate from interop: 12other ``ESObject`` typed variables, any, unknown, variables with anonymous type, etc. 13It is prohibited to initialize ``ESObject`` typed variable with statically typed value. 14Varaible of type ``ESObject`` can only be passed to interop calls and assigned to other 15variables of type ``ESObject``. 16 17 18## ArkTS 19 20 21``` 22 // lib.d.ts 23 declare function foo(): any; 24 declare function bar(a: any): number; 25 26 // main.ets 27 let e0: ESObject = foo(); // CTE - ``ESObject`` typed variable can only be local 28 29 function f() { 30 let e1 = foo(); // CTE - type of e1 is `any` 31 let e2: ESObject = 1; // CTE - can't initialize ESObject with not dynamic values 32 let e3: ESObject = {}; // CTE - can't initialize ESObject with not dynamic values 33 let e4: ESObject = []; // CTE - can't initialize ESObject with not dynamic values 34 let e5: ESObject = ""; // CTE - can't initialize ESObject with not dynamic values 35 let e6: ESObject = foo(); // OK - explicitly annotaded as ESObject 36 let e7 = e6; // OK - initialize ESObject with ESObject 37 e6['prop'] // CTE - can't access dynamic properties of ESObject 38 e6[1] // CTE - can't access dynamic properties of ESObject 39 e6.prop // CTE - can't access dynamic properties of ESObject 40 bar(e6) // OK - ESObject is passed to interop call 41 } 42``` 43 44 45## See also 46 47- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-identifiers-as-prop-names``) 48- Recipe 002: ``Symbol()`` API is not supported (``arkts-no-symbol``) 49- Recipe 029: Indexed access is not supported for fields (``arkts-no-props-by-index``) 50- Recipe 060: ``typeof`` operator is allowed only in expression contexts (``arkts-no-type-query``) 51- Recipe 066: ``in`` operator is not supported (``arkts-no-in``) 52- Recipe 137: ``globalThis`` is not supported (``arkts-no-globalthis``) 53 54 55