Type Generation#

OneJS provides TypeScript declarations for C# types so you get IntelliSense, autocomplete, and type checking in your editor.

Unity Types (unity-types)#

The unity-types npm package provides pre-generated declarations for standard Unity assemblies: CoreModule, UIElements, Physics, Audio, InputSystem, and more.

Install it as a dev dependency:

npm install -D unity-types

Once installed, your editor will provide IntelliSense for CS.UnityEngine.* types and ES6-style imports from Unity namespaces.

Project Types (JSRunner)#

For types from your own C# code (e.g., Assembly-CSharp), JSRunner has built-in auto-generation.

In the JSRunner inspector, find the Type Generation section. List the assemblies to include under Assemblies (for example Assembly-CSharp); Auto Generate is on by default.

Declarations are written to Output Path, types/csharp.d.ts in the working directory by default, which the scaffolded tsconfig.json already includes. They regenerate automatically on domain reload, which happens at editor startup and after any C# recompile, and Generate Types Now regenerates them on demand.

Globals (JSRunner)#

Every object in a JSRunner's Globals list is declared for you, in types/jsrunner.d.ts beside csharp.d.ts. Add a row with key ghostPrefab and a prefab as its value, and the file gains:

declare const ghostPrefab: CS.UnityEngine.GameObject

Each global is typed as its object's C# type when your typings declare that type. When they do not, for a component from your own code with Assembly-CSharp not listed under Assemblies, it is typed as the nearest base class they do declare, here CS.UnityEngine.MonoBehaviour, with a comment naming the real type. Add the assembly and it is typed exactly. A key that is not a valid identifier, like my-thing, cannot be declared; read it as globalThis["my-thing"].

The file is rewritten whenever the list changes in the inspector, on domain reload and with Generate Types Now, and only when its content changes, so the watcher does not rebuild for nothing. It needs no assemblies listed, and an app with an empty list has no such file. Do not edit it; change the list instead. If you declared a global by hand before, delete that line: the generated one replaces it and follows the list from now on.

Custom Packages (Type Generator Window)#

For third-party packages or specific assemblies, use the Type Generator window at Tools > OneJS > Type Generator.

The window has three panels: an assembly selector on the left, a type browser in the middle, and a live preview on the right. You can filter assemblies by category (Unity, User, etc.) and search for specific types.

Select the types you need and click Generate to save a .d.ts file. It is written to Assets/Gen/Typings/csharp/index.d.ts by default; set the output path to somewhere inside your app's ~/ folder (for example types/) so its tsconfig.json picks it up.

Programmatic API#

You can also generate declarations from C# scripts:

TypeGenerator.Create()
    .AddAssemblyByName("MyCustomPackage")
    .IncludeDocumentation()
    .Build()
    .WriteTo("types/my-package.d.ts");

This is useful for CI pipelines or editor tooling that needs to keep type declarations in sync automatically.

AddAssemblyByName and AddNamespace leave out test assemblies, the ones that reference NUnit, so a name that also matches your tests declares only your code. Pass includeTestAssemblies: true to take them too.