TypeScript
TypeScript copied to clipboard
[ID-Prep] Preserve all triple slash directives in declarations files
The [ID-prep] set of issues aligns Declaration Emit with the forthcoming Isolated Declarations feature.
🔍 Search Terms
preserve triple slash directives
✅ Viability Checklist
- [X] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [X] This wouldn't change the runtime behavior of existing JavaScript code
- [X] This could be implemented without emitting different JS based on the types of the expressions
- [X] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [X] This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- [X] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
Right now TypeScript will remove unused /// <reference types="..." />
directives.
📃 Motivating Example
// @declaration: true
// @filename: /a/node_modules/@types/node/index.d.ts
interface Error {
stack2: string;
}
// @filename: /a/app.ts
/// <reference types="node"/>
// ^ is currently removed
function foo(): Error {
return undefined;
}
💻 Use Cases
-
What do you want to use this for?
Preserving all references would make it easier for other tools to create the same output as typescript for declaration files
-
What shortcomings exist with current approaches?
Other tools don't have enough type information to determine if the reference is used or not if they only look at one file.
-
What workarounds are you using in the meantime?
Currently other tools can't emit declaration files.