-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Can't infer unique symbol types via another variable #35896
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
Comments
Just to make sure I understand. You're saying this works as you expect: let wideNumber: number;
const narrowNumber = wideNumber = 0;
// const narrowNumber: 0 👍 but this doesn't: let wideSymbol: symbol;
const narrowSymbol = wideSymbol = Symbol();
// const narrowSymbol: symbol 😕 Similarly, this works as you expect: const narrowNumber = 0;
// const narrowNumber: 0
const alsoNarrowNumber = narrowNumber;
// const alsoNarrowNumber: 0 👍 but this doesn't: const narrowSymbol = Symbol();
// const narrowSymbol: typeof narrowSymbol
const alsoNarrowSymbol = narrowSymbol;
// const alsoNarrowSymbol: symbol 😕 Right? |
Not my intent but probably legal. |
Probably somewhat related. Even identity functions aren't safe from them. ( |
Just hit a similar widening issue to this one and the one described by @AnyhowStep on #32242 (now closed). A function reduce<T>(fn: (value: T, acc: T) => T, initial: T): T {} String literal types are not widened by this construct, but |
Literals such as 0 can be inferred correctly but unique symbols are not.
TypeScript Version: 3.7.x-dev.20191224
Search Terms:
Code
Expected behavior:
Type rev is unique symbol.
Actual behavior:
Type rev is symbol. Can't even declare that rev is a unique symbol.
Playground Link: https://www.typescriptlang.org/play/index.html?ts=3.8.0-dev.20191224&ssl=1&ssc=1&pln=3&pc=18#code/DYUwLgBATiBuCWBneB7AdgLgogngWwCMVgBuAKAGN1FIZYIBeaOJVNRiAZXyOAAoAlOTqMGTOq3QkgA
Related Issues:
The text was updated successfully, but these errors were encountered: