Documentation menu

Use TypeScript

On this page
Guides0.1.0-alpha.36

Load the CLI package's declarations so your editor recognizes build options, maligator: imports, and runtime globals. Maligator strips erasable TypeScript; it does not type-check your application during a build.

Load the declarations

shell
npm install --save-dev @maligator/cli@alpha typescript

Include the build file in your TypeScript project, or explicitly load the package types:

tsconfig.json
{
	"compilerOptions": {
		"target": "ESNext",
		"lib": ["ESNext"],
		"module": "NodeNext",
		"strict": true,
		"noEmit": true,
		"allowImportingTsExtensions": true,
		"erasableSyntaxOnly": true,
		"types": ["@maligator/cli"]
	},
	"include": ["src/**/*.ts", "maligator.build.ts"]
}

An alternative for a project that manages types through declarations is /// <reference types="@maligator/cli" /> in a .d.ts file. If you already set compilerOptions.types, add the package to that list; an explicit list restricts automatic type loading.

Use ES modules

For the .ts examples in these guides, set the project package format:

shell
npm pkg set type=module

Run npm init --yes first if the project has no package.json. Maligator follows the nearest package's "type" for .js and .ts files. Use "module" for imports, exports, and top-level await; .mjs and .mts select ES modules by extension. .cjs and .cts select CommonJS.

Use erasable syntax

Write type annotations, interfaces, type aliases, and import type statements. Use .ts extensions for local TypeScript imports. Avoid syntax that needs runtime generation, including TypeScript enums and constructor parameter properties.

typescript
import { createPool, createWorkerUrl } from "maligator:workers";
import type { TaskContext } from "maligator:workers";

Run npx tsc --noEmit independently of maligator run. TypeScript catches type errors; Maligator checks compilation and runtime availability.

Type runtime APIs

The CLI declarations load Node types for timers, fetch, and other Web globals available in Node. Set "lib": ["ESNext"] for a server-only project. See Compatibility for the APIs Maligator implements.

Continue with Configure a build or the worker guide.

Maligator 0.1.0-alpha.36 · Experimental · Source 6af07bd09681
Edit this page · Compatibility

Search guides and API reference.

Browse the API · Troubleshooting