bhylu.com

Advertisements

TypeScript Node.js

TypeScript can check a Node program when the project includes appropriate Node declarations. Those declarations describe available APIs; Node itself still supplies their runtime implementation.

How it works

A local seed manifest needs a reproducible checksum. This example imports the built-in crypto module, hashes a fixed fictional label and compares the result with an independently computed known digest. The course review uses Node 22.15.1 and @types/node 22.20.5. Node declarations do not install Node, and a browser worker does not acquire Node APIs just because its source is written in TypeScript.

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 { createHash } from "node:crypto";
const digest = createHash("sha256").update("abc", "utf8").digest("hex");
console.log(digest);

Expected result

ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

The input is a fixed public fixture, not a password or secret. A checksum can identify accidental changes; it does not authenticate a sender without an appropriate keyed or signed protocol. Compile with the supplied Node types and run the emitted JavaScript locally.