Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type checking linear usage of disposables #90

Open
littledan opened this issue Sep 3, 2022 · 1 comment
Open

Type checking linear usage of disposables #90

littledan opened this issue Sep 3, 2022 · 1 comment
Labels
discussion Discussion topic, no immediate action required.

Comments

@littledan
Copy link
Member

littledan commented Sep 3, 2022

Resources which should be disposed of leads to potential room for type checkers (or linters) to help JS developers! I imagine this doesn't escape the author of this proposal, a top expert in JS type checking, but I'm curious about your thoughts in this area. The property that occurs to me is enforcing some part of "linearity", which I guess is not at all easy to check for, but I'm still wondering if it may be practical to implement part-way.

I wonder if type checkers could enforce that, you call a function which returns a disposable (e.g., DisposalStack.prototype.move), the caller should either use that in a using declaration or cause it to "escape" somehow or other (e.g., using it as an argument in a function, or storing it as a property in an object, but not randomly ignoring the return value of the function).

@rbuckton
Copy link
Collaborator

rbuckton commented Sep 7, 2022

We've considered something similar for Promises in TypeScript, and may do something similar for both in the future. The typescript-eslint plugin for ESLint has a no-floating-promises rule for Promises currently, so something like this is definitely possible.

@rbuckton rbuckton added the discussion Discussion topic, no immediate action required. label Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discussion topic, no immediate action required.
Projects
None yet
Development

No branches or pull requests

2 participants