JavaScript & TypeScript
Types, asynchronous code, modules and JavaScript runtime edge cases.
100 troubleshooting guides · Page 4 / 5
Why does destructuring a discriminated union sometimes lose payload narrowing?
Modern TypeScript can track certain const-destructured discriminants, but reassignment or separating correlated values can break that relationship.
Why is an array not accepted where a function requires a two-item tuple?
An array type does not guarantee length or positional types.
Why can JavaScript still mutate a TypeScript Readonly object?
Readonly is a compile-time restriction and is shallow.
Why does Partial not make nested update fields optional?
Partial transforms only the top-level properties.
How do I get the resolved return type of an async loader?
Use Awaited<ReturnType<typeof load>> on TypeScript versions supporting Awaited.
Why does a default argument widen the allowed values of a generic selector?
Inference may use both the choices and default arguments.
Why does a function overload reject a union argument accepted by its implementation?
Callers see overload signatures, not the implementation signature.
Why does a conditional type split a union into separate results?
A conditional over a naked type parameter distributes across union members.
Why does keyof on an enum not produce the enum member names?
For enum member names use keyof typeof Status: typeof obtains the enum object type, then keyof reads its keys.
Why does Object.values of a numeric enum contain both names and numbers?
Numeric enums emit reverse mappings.
How do I type event names derived from a fixed property-name union?
Use a template literal type when Field is a bounded string union: Keep runtime event registration synchronized with that model.
Why does adding a property to Window in one file not affect other modules?
A module-local interface does not automatically augment the global Window.
Why does TypeScript say document or fetch does not exist in a browser project?
Check the effective lib configuration and installed type packages.
Why do test globals disappear after setting compilerOptions.types?
An explicit types list limits which ambient packages are included.
Does skipLibCheck fix conflicting versions of a dependency’s types?
It skips declaration-file checking rather than reconciling incompatible definitions.
Why does TypeScript resolve an import that Node cannot load?
Module resolution must model the actual runtime or bundler.
Why does a relative TypeScript import need a .js extension in Node ESM?
The import specifier describes the runtime file that Node will load after compilation.
Why must I use import type after enabling verbatimModuleSyntax?
The compiler preserves imports according to explicit syntax.
Why does code pass tsc but fail a single-file transpiler?
Some TypeScript constructs need cross-file knowledge.
Why does importing JSON compile but fail in the deployed runtime?
resolveJsonModule supplies TypeScript resolution and types, not a universal runtime loader.
Why does a default import from a CommonJS package fail despite type-checking?
Inspect the package’s actual exports and the emitted interoperability helpers.
Why does an import work on Windows but fail in Linux CI?
Check filename casing against every import.
Why does rootDir report a file outside the source tree despite exclude?
Imported files become part of the program even when exclude filters discovery.
Why does a TypeScript path alias remain unresolved in compiled JavaScript?
paths helps TypeScript resolve names; it does not rewrite emitted specifiers.
Ask your own question · Sign in to post questions and answers.