-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
Search Terms
diagnosticsProducingTypeChecker
TypeChecker
getTypeChecker
Suggestion
Expose getDiagnosticsProducingTypeChecker.
Use Cases
A custom compiler adding additional checks must currently call:
// program: typescript.Program
const originalDiagnostics = program.get*Diagnostics(sourceFile);
const typeChecker: typescript.TypeChecker = program.getTypeChecker();
/* Use `typeChecker` to check the source file for additional diagnostics. */Internally, get*Diagnostics methods use getDiagnosticsProducingTypeChecker, so it is already "warmed" - types are already instantiated. The current implementation requires that a compiler pay the cost to instantiate types twice: once with a diagnosticsProducingTypeChecker, and once with a noDiagnosticsTypeChecker.
This would eliminate the redundant warm-up cost for instantiating types in the TypeChecker. This would be especially effective in code bases with deeply nested type definitions which may take noticeably longer to instantiate.
I do not fully understand the difference between the two TypeCheckers, so I cannot honestly comment on the drawbacks to exposing/using a diagnosticsProducingTypeChecker for custom checks (can someone please explain this, or point me towards documentation?). If it is unfeasible, perhaps there is a way to warm both checkers on the same run, to reduce the repeated type instantiations.
Examples
See Use Cases.
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript / JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. new expression-level syntax)