Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// 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<string>.const p: Promise<string> = transform("let x: number = 1;");void p;
// transform(iterable | async iterable) is an AsyncGenerator<string>.const ag: AsyncGenerator<string> = transform(["a", "b"]);void ag;const ag2: AsyncGenerator<string> = 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<string>.const g: Generator<string> = transformSync(["a", "b"]);void g;
// transformSync(Uint8Array chunks) is also fine: Chunk = string | Uint8Array.const g2: Generator<string> = 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" });
// jsx is a boolean; pragma and pragmaFrag are strings.transformSync("<a/>", { jsx: true, mode: "downlevel", pragma: "h", pragmaFrag: "Fragment" });// @ts-expect-error — jsx is not a string option.transformSync("<a/>", { jsx: "react" });
// 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" });