[ID-Prep] Preserve constant initializer in declarations as written in source #57443
Closed
6 tasks done
Labels
Domain: Isolated Declarations
Related to the --isolatedDeclarations compiler flag
Help Wanted
You can do this
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
The [ID-prep] set of issues aligns Declaration Emit with the forthcoming Isolated Declarations feature.
π Search Terms
const preserve initializer
β Viability Checklist
β Suggestion
TypeScript should only emit initializers in declaration files if the initializer is actually a literal type. Right now, TypeScript will emit an initializer for constants that are typed as a primitive literal type. This makes the emit behavior difficult to potentially emulate in other tools.TypeScript should emit initializers in declaration files as written in the source file.
π Motivating Example
π» Use Cases
This would improvement would can bring us closer to external declaration emitters being a reality.
We would need to detect the case of a primitive literal initializer anyway in order to make
const bar = foo;
an error with isolated declarations anyway. Preserving the original type node seems like a win for both source map and declaration fidelity.We could only raise the error and not change the current emit.
The text was updated successfully, but these errors were encountered: