microsoft / microsoft/TypeScript

Suggestion: Derive disposability checks from known symbols rather than global interfaces

Abierto
#62,121 0 comentarios 3 reacciones 1 asignado Ver en GitHub

Nadie ha tomado este issue todavía.

Experimentation Needed Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

Acknowledgement
  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
Comment

When it comes to checking for disposability (for use with using/await using declarations), the checker fetches the global Disposable/AsyncDisposable symbol and runs an assignability test against its type.

This is mostly fine, but this interface is user-mutable, so any script in the project which plays with these interfaces can unintentionally modify the checker's behaviour. For example, a module might declare an empty global interface for backwards compatibility:

declare global {
  interface Disposable {}
}

export interface MyResource extends Disposable {
  ...
}

...which means that all disposability tests will now return true within the checker, if there's no lib.esnext.disposable or similar to populate the interface.

Other checker processes that rely on well-known symbols tend to interrogate the symbol-keyed properties directly, rather than test against global types – for example, iteration checks first fetch the well-known Symbol.iterator via getPropertyNameForKnownSymbolName, then use this index to access the iteration method on the target type.

While not critical, it would be an improvement if the checker could test against the Symbol.dispose/Symbol.asyncDispose properties directly, rather than testing for assignability against the global interface.

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.