Open littledan opened 2 years ago
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.
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 ausing
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).