Files
scriptc/tests/diagnostics/zlib-class-alias-escape.ts
T
Chris Tate b4ef932b72 Support zlib stream classes as const aliases and instanceof targets
`const C = zlib.Gzip` stopped at SC2020, and `instanceof zlib.Gzip`
(any zlib class) stopped at SC1090. A const binding of a zlib class is
now a compile-time alias with no runtime slot: `new C()`, `typeof C`,
`C.name` and `C === zlib.Gzip` lower at the use. `instanceof` against a
zlib class asks the runtime for the stream's mode when the operand is a
Transform, tests for a Transform first when it is typed as one of
Transform's bases, and answers false for other static types, as in Node.
Other uses of an alias as a value report SC1090 at the use.
2026-10-18 09:52:17 -05:00

12 lines
370 B
TypeScript

// A zlib class alias owns no runtime value: construction, instanceof,
// typeof and .name compile, other uses report at the use. instanceof on
// an untyped operand reports as well.
import * as zlib from "node:zlib";
const Gz = zlib.Gzip;
const classes = [Gz];
console.log(classes.length);
const parsed: unknown = JSON.parse("{}");
console.log(parsed instanceof Gz);