TypeScript Advanced Declaration Authoring

Declaration inference regression tests

A type regression test should assert an observable consumer contract, not simply compile an unused value. A generic identity preserves the literal input in this example. A replacement signature that widens the result to string produces a diagnostic even though the runtime still returns the same string. This is a targeted inference check, not a proof of universal type equality. Baseline: TypeScript 5.8.3, strict NodeNext consumer unless otherwise noted. Create the labeled files separately; do not paste this project into a single-file editor.

Formal Syntax & Structure

typescript syntaxtypescript
const exact: "ok" = make("ok" as const);

Working Example

Example Snippettypescript
// File: tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "NodeNext",    "moduleResolution": "NodeNext",    "strict": true,    "types": [],    "lib": [      "ES2022",      "DOM"    ],    "noEmitOnError": true  },  "files": [    "main.cts"  ]}
// File: node_modules/demo/package.json (omit this label){  "name": "demo",  "version": "1.0.0",  "main": "./index.cjs",  "types": "./index.d.cts"}
// File: node_modules/demo/index.d.cts (omit this label)export function make<T>(value: T): T;
// File: node_modules/demo/index.cjs (omit this label)exports.make = value => value;
// File: main.cts (omit this label)import { make } from "demo";const value = make("ok" as const);const exact: "ok" = value;console.log(exact);
// Run: tsc -p . --pretty false// Expected: no diagnostics.// Run: node main.cjs// Expected stdout: ok
TypeScript Reference