You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Template string wrongly infers type from a default value used in destructuring assignmentΒ #55907
typeParams={value?: string|number}functionexample(parameters: Params){const{ value ='123'}=parametersreturn`${value}`==='345'// <--- Error: This comparison appears to be unintentional because the types '"123"' and '"345"' have no overlap.(2367)}
π Actual behavior
The template string expression, ${value}, is assigned type "123", based on a default value assigned to value in a destructing assignment.
π Expected behavior
The expression should instead be assigned a type of string. The field value is correctly assigned a type of string | number, so any template string using value should not be restricted to the default value used in destructuring.
changed the title [-]Template strings wrongly infer type from a default value used in destructuring assignment[/-][+]Template string wrongly infers type from a default value used in destructuring assignment[/+]on Sep 29, 2023
Activity
[-]Template strings wrongly infer type from a default value used in destructuring assignment[/-][+]Template string wrongly infers type from a default value used in destructuring assignment[/+]Andarist commentedon Sep 29, 2023
I'm almost certain that this is a fall out of #53907 and it's definitely a bug. I'll look into this soon.
LasAtt commentedon Sep 29, 2023
Thank you for looking into it!
Andarist commentedon Sep 29, 2023
It's actually an old bug but this one is a new manifestation of it. TS playground