Programming Language Support

    Cocos Creator supports TypeScript 4.1.0. The following restrictions are based on TypeScript 4.1.0:

    • will not be read. The following options are implied for each project:

      The implicit isolatedModules option means that:

      • is not supported.

      • Use export type when re-exporting TypeScript types and interfaces. For example, use export type { Foo } from '. /foo'; instead of export { Foo } from '. /foo';.

    • export = and import = are not supported.

    • Different declarations in the same namespace do not share scope and require explicit use of qualifiers.

    • Type errors during compilation will be ignored.

    tsconfig.json is not read at compile time, meaning that the compile option for tsconfig.json does not affect compilation.

    Developers can still use tsconfig.json in their projects to work with the IDE to implement features such as type checking. In order to make the IDE’s TypeScript checking compatible with the behavior of Creator, developers need to pay some extra attention to tsconfig.

    JavaScript

    The JavaScript language specification supported by Creator is ES6.

    In addition, the following language features or proposals, updated to the ES6 specification, are still supported.

    In particular, Creator currently supports Legacy decorator proposals, see for their usage and meaning. Since this proposal is still in phase 2, all decorator-related functional interfaces exposed by the engine are under the _decorator namespace starting with an underscore.

    Creator opens some compilation options that will be applied to the entire project.

    From the user’s perspective, Creator does not bind any JavaScript implementation, so it is recommended that developers write scripts strictly according to the JavaScript specification for better cross-platform support.

    For example, when wishing to use global objects, the standard feature globalThis should be used:

    instead of window, global, self or this:

    Again, Creator does not provide a module system for CommonJS, so the following code snippet would pose a problem: