-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
Currently the polyfilled implementation for using
performs the following check:
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
if (value !== null && value !== void 0) {
if (typeof value !== "object") throw new TypeError("Object expected.");
// ...
In the spec, the value used with using
needs to be an "Object type", but we know in JavaScript an Object type can have typeof
value other than "object"
, for example, a function has typeof value === "function"
while also being a valid JavaScript Object.
The implementation should use the check similar to underscore.js
's isObject()
check:
export default function isObject(obj) {
var type = typeof obj;
return type === 'function' || (type === 'object' && !!obj);
}
⏯ Playground Link
function createHandle(): Writer & Disposable {
const write: Writer = (data) => {};
const close = (): void => {};
return Object.assign(write, { [Symbol.dispose]: close });
}
{
using write = createHandle();
}
type Writer = {
(data: string): void;
};
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue