microsoft / microsoft/TypeScript

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

Open
#62,121 0 comments 3 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

Experimentation Needed Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.