bhylu.com

Advertisements

TypeScript tsconfig.json

A tsconfig.json describes a project’s files and compiler options. Run tsc -p against that project instead of mixing a configuration file with an unrelated list of command-line source files.

How it works

This example uses the course’s strict project settings: strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes, noImplicitOverride and noEmitOnError. The generated download includes the matching tsconfig.json. An indexed lookup can miss even when the array itself is valid, so its result includes undefined. A guard makes that possibility visible. Target controls emitted language features; it does not install runtime polyfills or make an old browser support a new API.

Run the code

Try in playground loads this source without running it. Choose Run when ready. The existing TypeScript 5.8.3 worker transpiles and executes one file; it does not perform full semantic type checking, load npm imports or provide DOM/Node APIs. Use the local compiler for the type contract.

For a full check, save the three downloads together in a new folder, run npm install, then npm run check. Use npm run build followed by npm start to execute the checked JavaScript with Node. The supplied project enables strict checking, indexed-access checks and exact optional properties.

Example

lesson.ts

const labels: string[] = ["Bean", "Pea"];
const chosen = labels[3];
console.log(chosen === undefined ? "No label at that position" : chosen);

Expected result

No label at that position

The out-of-range position produces undefined at runtime, and the strict indexed-access option makes the checker require a decision before using it as text. In your local folder run npx tsc -p tsconfig.json and then node out/lesson.js. Bhylu’s review compiles the same source with these settings; the browser runner does not use your tsconfig file.