-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
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)
squirly, sindresorhus, yume-chan and ExE-Boss
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript