Open
Description
π Search Terms
unique symbol widening
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
const u = Symbol();
const a7 = u as typeof u // widened to symbol
π Actual behavior
a7
is symbol
π Expected behavior
a7
has typeof u
Additional information about the issue
This issue is a huge problem for isolated declarations as it breaks the assumption that in an expression const o = a as T
we can always use T
as the type of o
. This is also inconsistent with the way similar expressions work for string/number literal types (ex)
Similar issues:
unique symbol
type lost after property is extracted from an objectΒ #43657 - Widening on return type not on variable declaration- Explicitly annotated unique symbols are widened in return positionsΒ #55361 - Similar, explicitly typed variable is widened
- Symbol type is incorrectly generalized when used as a property value of an object literalΒ #36876 - Widening when assigning from object property (but no assertion)
unique symbol
s from the globalSymbolConstructor
widen way too eagerlyΒ #53276