Open
Description
Search Terms
Suggestion
Assigning a known symbol constant to another constant should retain type information.
const foo = Symbol() // known symbol
const bar = foo // expecting 'typeof foo' but received 'symbol'
interface UseFoo {
[foo]: 'value'
}
// This should work
const useBar: UseFoo = {
[bar]: 'value'
}
Use Cases
Creating aliases of symbol constants without losing type information.
Examples
Symbol.iterator
alias
const { iterator } = Symbol
const iterable: Iterable<number> = {
* [iterator] () {
yield * [0, 1, 2, 3]
}
}
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript / JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. new expression-level syntax)