`unique symbol` is now lost when accessed through a property
Opened this issue · 1 comments
arcanis commented
Steps to reproduce
function foo() {}
const mySymbol = Symbol();
foo.sym = mySymbol;
const shouldWork: typeof mySymbol = foo.sym;Behavior with typescript@5.8
Works in 5.8 / 5.9:
Behavior with tsgo
main.ts(6,7): error TS2322: Type 'symbol' is not assignable to type 'unique symbol'.
Weirdly the hover properly returns typeof mySymbol when hovering sym, but tsgo is still unhappy. My workaround is to make the type explicit using an as cast in the property assignment:
ahejlsberg commented
I'm actually surprised at the Strada behavior. Consider:
const mySymbol = Symbol();
let sym = mySymbol; // Widened to type symbol
const shouldWork: typeof mySymbol = sym; // ErrorThe above is an error with both Strada and Corsa because we widen the unique symbol type when inferring from an initializer for a mutable location. Since the foo.sym expando property is indeed a mutable location, I'd expect widening (and thus the follow-on error) to occur in the original example, as it does with the new compiler. So, I think this is actually a bug/inconsistency in the old compiler.