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