Skip to content

[ID-Prep] Preserve all triple slash directives in declarations filesΒ #57439

Closed
@dragomirtitian

Description

@dragomirtitian

The [ID-prep] set of issues aligns Declaration Emit with the forthcoming Isolated Declarations feature.

πŸ” Search Terms

preserve triple slash directives

βœ… Viability Checklist

⭐ 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;
}

Playground

πŸ’» Use Cases

  1. 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

  2. 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.

  3. What workarounds are you using in the meantime?

    Currently other tools can't emit declaration files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeWould introduce errors in existing codeBugA bug in TypeScriptFix AvailableA PR has been opened for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions