Use this:
declare function Symbol (x?: string | number): symbol
declare namespace Symbol {
const prototype: symbol
const iterator: unique symbol
}
Or this:
interface SymbolConstructor {
(x?: string | number): symbol
readonly prototype: symbol
readonly iterator: unique symbol
}
declare var Symbol: SymbolConstructor
Instead of this:
interface SymbolConstructor {
(x?: string | number): symbol
readonly prototype: symbol
readonly iterator: symbol
}
declare var Symbol: SymbolConstructor
Right now, I can do this for custom unique symbol:
const foo = Symbol() // unique symbol
const bar: typeof foo = foo
const baz: {
[foo]: number
} = {
[bar]: 123
}
But not for Symbol.*
// Expecting 'typeof Symbol.iterator' but received 'symbol'
const iterator: typeof Symbol.iterator = Symbol.iterator
// This is not working
const iterable: Iterable<number> = {
* [iterator] () {
yield * [0, 1, 2, 3]
}
}
My suggestion meets these guidelines:
Playground Link (This also works)
@rbuckton what are your thoughts on this?
This is something we plan to do, but requires us to support "typesVersions" on DefinitelyTyped so that we can address the forward-declaration of Symbol.iterator, etc. in the type definitions for NodeJS, core-js, and es6-shim.
https://github.com/Microsoft/TypeScript/pull/24738 also works around the old-lib issue by considering any symbols under the global Symbol constructor as unique symbols.
https://github.com/microsoft/TypeScript/pull/24738 would fix this in a manner that鈥檚 compatible with old .d.ts files.
Most helpful comment
This is something we plan to do, but requires us to support
"typesVersions"on DefinitelyTyped so that we can address the forward-declaration ofSymbol.iterator, etc. in the type definitions for NodeJS, core-js, and es6-shim.