mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 22:32:33 -05:00
fix(54951): using being too strict to throw on Function type (#54969)
This commit is contained in:
@@ -1403,7 +1403,7 @@ export const addDisposableResourceHelper: UnscopedEmitHelper = {
|
||||
text: `
|
||||
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
||||
if (value !== null && value !== void 0) {
|
||||
if (typeof value !== "object") throw new TypeError("Object expected.");
|
||||
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
||||
var dispose;
|
||||
if (async) {
|
||||
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
||||
|
||||
@@ -1658,4 +1658,29 @@ describe("unittests:: evaluation:: usingDeclarations", () => {
|
||||
"after block"
|
||||
]);
|
||||
});
|
||||
|
||||
it("'using' for 'function' disposable resource ", () => {
|
||||
const { main, output } = evaluator.evaluateTypeScript(`
|
||||
export const output: any[] = [];
|
||||
|
||||
function disposable() {
|
||||
const f = () => output.push("enter");
|
||||
const d = () => output.push("exit");
|
||||
return Object.assign(f, { [Symbol.dispose]: d });
|
||||
}
|
||||
|
||||
export function main() {
|
||||
using run = disposable();
|
||||
run();
|
||||
}
|
||||
|
||||
`, { target: ts.ScriptTarget.ES2018 });
|
||||
|
||||
main();
|
||||
|
||||
assert.deepEqual(output, [
|
||||
"enter",
|
||||
"exit",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user