20. Implementation Details

Important implementation details are discussed in this section.

20.1. Import Path Lookup

If an import path <some path>/name is resolved to a path in the folder “name”, then the compiler executes the following lookup sequence:

  • If the folder contains the file index.ets, then this file is imported as a separate module written in ArkTS;

  • If the folder contains the file index.ts, then this file is imported as a separated module written in TypeScript;

  • Otherwise, the compiler imports the package constituted by files name/*.ets.

20.2. How to get type via reflection

The ArkTS standard library (see Standard Library) provides a pseudo generic static method ‘Type.for<T>()’ to be processed by the compiler in a specific way during compialtion. A call to this method allows getting a variable of type Type that represents type T at runtime. Type T can be any valid type.

 1 let type_of_int: Type = Type.for<int>()
 2 let type_of_string: Type = Type.for<String>()
 3 let type_of_array_of_int: Type = Type.for<int[]>()
 4 let type_of_number: Type = Type.for<number>()
 5 let type_of_Object: Type = Type.for<Object>()
 6
 7 class UserClass {}
 8 let type_of_user_class: Type = Type.for<UserClass>()
 9
10 interface SomeInterface {}
11 let type_of_interface: Type = Type.for<SomeInterface>()