Modules and several files
Split a program into .ts files with import and export; no npm packages.
Runs in Zerethon IDE · TypeScript 7
Official TypeScript documentation ↗
main.ts
import { area, type Size } from './geometry';
const size: Size = { width: 3, height: 4 };
console.log(area(size));
geometry.ts
export interface Size {
width: number;
height: number;
}
export function area(size: Size): number {
return size.width * size.height;
}
Output
12
main.ts (the entry) and geometry.ts. Import without the extension.
- All
.tsfiles of the project are compiled together, so a type error in any file stops the run. - Node's built-in modules and their types are available (
fs,path,readline, …). - Compiler options are fixed (strict, ES2022, CommonJS output); a
tsconfig.jsonin the project is ignored. - npm packages are not available: runs have no network and nothing is installed.