Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect widening of literal types in emitted .d.ts for export default/export assignments, aligning tsgo’s declaration output and incremental behavior more closely with TypeScript’s (and removing previously-recorded expected diffs).
Changes:
- Preserve literal types when serializing types for
exportassignments (avoids widening1/"string"/42tonumber/string). - Adjust pseudotype literal handling to avoid forcing widening via the “big shortcut”.
- Update/clean up reference baselines and incremental test expectations now that diagnostics and signatures are correct.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/checker/nodebuilderimpl.go | Avoids widening literal types when serializing types for export assignments. |
| internal/checker/pseudotypenodebuilder.go | Stops widening for pseudotype literal mapping to prevent incorrect literal loss. |
| internal/execute/tsctests/tsc_test.go | Removes prior expectedDiff now that the underlying issue is fixed. |
| testdata/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file.js | Baseline update: default export retains literal type; incremental diagnostics/signatures updated. |
| testdata/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file-through-indirect-import.js | Baseline update: same as above, via re-export chain. |
| testdata/baselines/reference/tsc/composite/synthetic-jsx-import-of-ESM-module-from-CJS-module-no-crash-no-jsx-element.js | Baseline update: default export literal type preserved (42). |
| testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault(target=es2015).js | Baseline update: default export literal type preserved (12). |
| testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault(target=es2015).js.diff | Baseline diff updated to reflect convergence. |
| testdata/baselines/reference/submodule/compiler/nodeNextCjsNamespaceImportDefault2.js | Baseline update: default export string literal preserved ("string"). |
| testdata/baselines/reference/submodule/compiler/nodeNextCjsNamespaceImportDefault2.js.diff | Baseline diff removed/updated due to convergence. |
| testdata/baselines/reference/submodule/compiler/modulePreserve4.js | Baseline update: preserves 0 literals for relevant default exports. |
| testdata/baselines/reference/submodule/compiler/modulePreserve4.js.diff | Baseline diff updated to reflect convergence. |
| testdata/baselines/reference/submodule/compiler/dynamicImportsDeclaration.js | Baseline update: preserves literal defaults (0, 1, "fallback"). |
| testdata/baselines/reference/submodule/compiler/dynamicImportsDeclaration.js.diff | Baseline diff removed/updated due to convergence. |
| testdata/baselines/reference/compiler/jsdocCommentDefaultExport(module=esnext).js | Baseline update: preserves literal type in default export with JSDoc. |
| testdata/baselines/reference/compiler/jsdocCommentDefaultExport(module=commonjs).js | Baseline update: preserves literal type in default export with JSDoc. |
| // `const _default: <type>`, and a const should preserve the literal type. | ||
| // Strada handles this via preserveLiterals in the syntactic type builder; | ||
| // we handle it by not widening the checker type in the first place. | ||
| if !ast.IsExportAssignment(declaration) { |
There was a problem hiding this comment.
serializeTypeForDeclaration skips literal widening only for ast.IsExportAssignment(declaration), but declaration can also be a KindJSExportAssignment (synthetic module.exports = ...) in the declarations transformer. Those cases also emit a const _default: <type> wrapper and should preserve literal types as well. Consider using ast.IsAnyExportAssignment(declaration) (or checking IsExportAssignment || IsJSExportAssignment) so CJS export-assignments don’t continue to widen.
| if !ast.IsExportAssignment(declaration) { | |
| if !ast.IsAnyExportAssignment(declaration) { |
Two things:
preserveLiterals.