-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Support symbol properties on namespaces #36813
Comments
Seems like this is mostly meant for the function blah() {
}
blah[Symbol.iterator] = 100; One problem that @weswigham brought up with this is that assuming you're repurposing export namespace foo {
export let [xyz] = 10; // currently parses as a binding pattern
} |
#40594 could probably help with this by allowing the following in namespaces: declare namespace Reflect {
const toStringTag: "Reflect";
export { toStringTag as [Symbol.toStringTag] };
}
Yes, this is intended for the // foo.ts
const kSymbol = Symbol('symbol');
function blah() {
// ...
}
blah.foo = 'foo';
blah[kSymbol] = 100; // generated foo.d.ts
declare const kSymbol: unique symbol;
declare function blah(): void;
declare namespace blah {
var foo: string;
} // expected foo.d.ts
declare const kSymbol: unique symbol;
declare function blah(): void;
declare namespace blah {
export var foo: string;
var _kSymbol: number;
export { _kSymbol as [kSymbol] };
} |
I don't see how |
I mean only allowing it in TypeScript’s |
😦 |
This defines properties on each of the exported asynchronous functions which allow them to work with Node's `promisify`. The existing callbacks were incompatible by default, because they: • are not given as the last arguments of those functions • do not accept optional "error" as their first arguments In other words, they are not "Node-style". This implementation chooses to reject promises rather than returning `undefined` on those errors, as the callbacks do: presumably the `undefined` value is used simply because the existing callback format forgot to allow for an error parameter. This defines both the modern `promisify.custom` symbol and the "old" `__promisify__` property, since the former isn't actually describable in TypeScript definitions yet, and the latter is still used in Node's definition files (e.g. for `child_process` functions). See: • microsoft/TypeScript#36813 • DefinitelyTyped/DefinitelyTyped#42154
This defines properties on each of the exported asynchronous functions which allow them to work with Node's `promisify`. The existing callbacks were incompatible by default, because they: • are not given as the last arguments of those functions • do not accept optional "error" as their first arguments In other words, they are not "Node-style". This implementation chooses to reject promises rather than returning `undefined` on those errors, as the callbacks do: presumably the `undefined` value is used simply because the existing callback format forgot to allow for an error parameter. This defines both the modern `promisify.custom` symbol and the "old" `__promisify__` property, since the former isn't actually describable in TypeScript definitions yet, and the latter is still used in Node's definition files (e.g. for `child_process` functions). See: • microsoft/TypeScript#36813 • DefinitelyTyped/DefinitelyTyped#42154
This defines properties on each of the exported asynchronous functions which allow them to work with Node's `promisify`. The existing callbacks were incompatible by default, because they: • are not given as the last arguments of those functions • do not accept optional "error" as their first arguments In other words, they are not "Node-style". This implementation chooses to reject promises rather than returning `undefined` on those errors, as the callbacks do: presumably the `undefined` value is used simply because the existing callback format forgot to allow for an error parameter. This defines both the modern `promisify.custom` symbol and the "old" `__promisify__` property, since the former isn't actually describable in TypeScript definitions yet, and the latter is still used in Node's definition files (e.g. for `child_process` functions). See: • microsoft/TypeScript#36813 • DefinitelyTyped/DefinitelyTyped#42154
This defines properties on each of the exported asynchronous functions which allow them to work with Node's `promisify`. The existing callbacks were incompatible by default, because they: • are not given as the last arguments of those functions • do not accept optional "error" as their first arguments In other words, they are not "Node-style". This implementation chooses to reject promises rather than returning `undefined` on those errors, as the callbacks do: presumably the `undefined` value is used simply because the existing callback format forgot to allow for an error parameter. This defines both the modern `promisify.custom` symbol and the "old" `__promisify__` property, since the former isn't actually describable in TypeScript definitions yet, and the latter is still used in Node's definition files (e.g. for `child_process` functions). See: • microsoft/TypeScript#36813 • DefinitelyTyped/DefinitelyTyped#42154
I believe this limitation prevents us from supplying types like const exampleKey = Symbol();
globalThis[exampleKey] = 1; since |
Search Terms
Suggestion
The ability to declare symbol properties on TypeScript namespaces.
Use Cases
See DefinitelyTyped/DefinitelyTyped#42154 (comment).
Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: