microsoft / microsoft/TypeScript

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

Ouverte
#62,121 0 commentaires 3 réactions 1 personne assignée Voir sur GitHub

Personne n'a encore pris cette issue.

Experimentation Needed Suggestion
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.