The specific APIs for instances depends on the plugin type. These interfaces are all documented in the scripting reference section of the manual, such asISpriteInstance for Sprite instances, which provides APIs for things like animations. Note that these interfaces also inherit fromIWorldInstance andIInstance (depending on the kind of plugin). For example common properties likex andy are part ofIWorldInstance.
Construct further generates a type definition for every object type in the project, such asInstanceType.Player for a Sprite object namedPlayer. This will derive fromISpriteInstance but add type definitions for the instance variables, behaviors and effects specific to that object type, ensuring they are autocompleted and type checked correctly. When writing TypeScript code you may wish to use a specific type likeInstanceType.Player if you want to refer to a specific object type, or a more general type likeISpriteInstance orIWorldInstance depending on whether that code is more generally applicable.
Integrating scripts and events
Strings and numbers can be exchanged between event sheets and TypeScript code using global and local variables in event sheets. Local variables are accessible vialocalVars inside scripts in event sheets, and global variables are accessible viaruntime.globalVars. There is more information in the manual section onScripts in event sheets.
Strings and numbers can also be exchanged via instance variables via theinstVars property ofIInstance. (As noted previously Construct generates type definitions for each kind of object type which will include all the available instance variables.)
See also the example projectIntegrating events with script for an example of some useful techniques.
Using an external editor
Construct has special features to let you use an external code editor like VS Code to write your project's code if you prefer. Note that the workflow is different to working within the Construct editor itself, and involves exporting your project's type definitions. See the guideUsing an external editor.
Learn more
Here are some more resources to learn more about using TypeScript in Construct.
Examples
There are lots of example projects using TypeScript coding in Construct which you can find in theScripting category in theExample Browser.
Debugging
You can still use the browser developer tools to debug code that you write in Construct. Note that the debugger will show the compiled JavaScript output of your TypeScript code, but that generally looks the same but just without the type annotations. For a quick-start guide on debugging, see the manual section onDebugging script.
Minifying
Minifying on export also applies to your TypeScript code written in Construct. When minifying, your TypeScript code is first compiled to JavaScript, and then the minification performed on the resulting JavaScript. Code minification is done with the industry-standard libraryterser.Simple minify mode should never affect how your code runs. However if you enableAdvanced minify mode on export, you may need to adjust how you write your code. See the manual guide onExporting with Advanced minification for more details.
Worker mode
Construct is capable of running its entire engine in a Web Worker, rendering via OffscreenCanvas. However by default projects using TypeScript code run in the main page ("DOM mode") to ensure compatibility with code that expects to be able to use DOM features likedocument. If your TypeScript code is compatible with running in a Web Worker, you can re-enable worker mode for improved performance by changing the project propertyUse worker toYes (in theAdvanced section). When you do this, Construct will also adjust the provided type definitions to match a worker context, so accessing DOM-specific APIs likedocument will be marked as an error. There is more information about this in the manual sectionJavaScript in Construct.
Reference
See theScripting section of the manual for full documentation on using TypeScript in Construct.