microsoft / microsoft/TypeScript

Preserve interfaces in generated declaration files for augmentation

Abierto
#42,853 7 comentarios 2 reacciones 1 asignado Ver en GitHub

@weswigham ya está trabajando en esto.

Desde el 18/2/2021.

Needs Investigation
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

Suggestion

2023 Updat

We investigated this, and turns out its easy to workaround, just extract function's type into standalone type declaration. So its low priority for us now.

🔍 Search Terms

Stop emitting never for empty interfaces from declaration

✅ Viability 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. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • [ X This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Make TypeScript compiler preserve references to original Interfaces. (or at very least add an option for this!)

📃 Motivating Example

Playgroud link

export interface InterfaceToAugment {

}

export default <T extends keyof InterfaceToAugment>(key: T, value: InterfaceToAugment[T]) => { };

After we run tsc (with declaration: true of course) we'll see our .d.ts file:

export interface InterfaceToAugment {
}
declare const _default: <T extends never>(key: T, value: InterfaceToAugment[T]) => void;
export default _default;

As you can see here, declaration file making this interface absolutely useless., but I wanted to make this function to pick real keys of this interface.

Is there any workaround for this?

💻 Use Cases

Module Augmentation for library consumer

declare module "this-lib" {
  interface InterfaceToAugment {
    myCustomKey: 5
  }
}

Please, correct me if I missed something

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.