// Typechecks src/index.d.ts's overloads with the project's own `typescript` devDependency. // Usage: pnpm test:types (node_modules/.bin/tsc --noEmit test/types-check.ts) // Not run with the rest of the suite's semantics in mind: this file only needs to compile, // never to run, so a type error here is the test failing. import { transform, transformSync, engine, UnsupportedSyntaxError } from "../src/index.js"; // transform(string) is a Promise. const p: Promise = transform("let x: number = 1;"); void p; // transform(iterable | async iterable) is an AsyncGenerator. const ag: AsyncGenerator = transform(["a", "b"]); void ag; const ag2: AsyncGenerator = transform((async function* () { yield "a"; })()); void ag2; // transformSync(string) is a string. const s: string = transformSync("let x: number = 1;"); void s; // transformSync(iterable) is a Generator. const g: Generator = transformSync(["a", "b"]); void g; // transformSync(Uint8Array chunks) is also fine: Chunk = string | Uint8Array. const g2: Generator = transformSync([new Uint8Array([1, 2, 3])]); void g2; // mode and onError are optional, and mode is a closed union. transform("x", { mode: "downlevel", onError: (e) => { const _s: number = e.start; const _en: number = e.end; } }); transformSync("x", { mode: "erase" }); // engine() returns an object with a memory export, usable for tests/profiling. const mem: WebAssembly.Memory = engine("erase").memory; void mem; // UnsupportedSyntaxError exposes code/start/end. const err = new UnsupportedSyntaxError(0, 1); const _code: "ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX" = err.code; void _code; // @ts-expect-error — an async iterable is a type error for transformSync, not just a runtime one. transformSync((async function* () { yield "a"; })()); // @ts-expect-error — an unknown mode string is rejected at the type level. transform("x", { mode: "transform" });