You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// @ts-expect-errorSymbol.dispose=Symbol();constfn: any=()=>{};fn[Symbol.dispose]=()=>console.log("dispose");
using handle=fn;
If we run through esbuild:
-> % npx esbuild --target=node18 test.ts | node
[stdin]:40
throw error;
^
TypeError: Object expected
at __using ([stdin]:10:13)
at [stdin]:50:16
at Script.runInThisContext (node:vm:129:12)
at Object.runInThisContext (node:vm:313:38)
at node:internal/process/execution:79:19
at [stdin]-wrapper:6:22
at evalScript (node:internal/process/execution:78:60)
at node:internal/main/eval_stdin:30:5
at Socket.<anonymous> (node:internal/process/execution:195:5)
at Socket.emit (node:events:525:35)
Node.js v18.12.1
esbuild requires that the disposable resource is an object (not function):
// [...]
if (typeof value !== "object")
throw TypeError("Object expected");
Thanks for the report. Looks like TypeScript recently changed their implementation of this feature: microsoft/TypeScript@02e8d5e. I can update esbuild to match the new behavior.
cpiro
added a commit
to cpiro/esbuild
that referenced
this issue
Sep 16, 2023
Given the source file:
If we run through esbuild:
esbuild requires that the disposable resource is an object (not function):
From TypeScript it executes cleanly:
The emitted file from tsc explicitly handles the function case:
Relevant specification doesn't say that the disposable may not be a function:
https://tc39.es/proposal-explicit-resource-management/#sec-getdisposemethod
The text was updated successfully, but these errors were encountered: