bhylu.com

Advertisements

TypeScript DefinitelyTyped

DefinitelyTyped provides community-maintained declarations for many JavaScript packages. They are commonly installed as @types packages; libraries that ship their own declarations usually do not need an extra one.

How it works

Node’s runtime APIs are described separately by @types/node. The example imports a typed timer promise and awaits its result. Choose declarations that match the major runtime or library contract you actually use. A package-manager lockfile makes that choice reproducible, but it does not prove a third-party declaration is correct in every case.

Run the code

This example runs locally with its documented files and dependencies. It cannot run in the single-file browser worker. Save every download under its shown name in one new folder, run npm install, npm run build, then npm start. The course review compiles and executes the actual files, not just an inline replacement.

Use npm run check for a separate no-output compiler pass. The supplied project enables strict checking, indexed-access checks and exact optional properties. Node fixtures use Node 22.15.1; React fixtures use React/React DOM 19.3.1. These dependencies are installed only in your new example folder, not into Bhylu’s application.

Example

lesson.ts

import { setTimeout as pause } from "node:timers/promises";
async function main(): Promise<void> {
  const state = await pause(1, "Ready for collection");
  console.log(state);
}
main().catch(error => { console.error(String(error)); });

Expected result

Ready for collection

The timer returns a Promise of the supplied string value. The tiny delay is not a timing assertion; the expected result concerns only the resolved value. This fixture uses the installed Node declarations and real Node implementation. Browser timer types and Node timer types can differ, so do not combine environments accidentally.