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
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.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
LasAtt
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
Sep 29, 2023
π Search Terms
"template string", "default value", "infer type", "destructuring"
π Version & Regression Information
This changed between versions
5.1.6
and5.2.2
. The bug is also present in5.3.0-dev.20230928
.β― Playground Link
https://www.typescriptlang.org/play?ts=5.3.0-dev.20230928#code/C4TwDgpgBACghgJzgWwM5QLxQN4CgpQBucANgK4QD8AXFKsAgJYB2A5lAD5TNnIBGEBLgC+uXADMyzAMbBGAe2ZQIADxRgSEABRhEKCMEGpa8JGgCUOfFGmL6OIqQqYoAcgCMAJgDMrqMJddMwMjawQDMgQlAAMAEmxicghhaMwMLFdvABYAVlcRXCA
π» Code
π Actual behavior
The template string expression,
${value}
, is assigned type"123"
, based on a default value assigned tovalue
in a destructing assignment.π Expected behavior
The expression should instead be assigned a type of
string
. The fieldvalue
is correctly assigned a type ofstring | number
, so any template string usingvalue
should not be restricted to the default value used in destructuring.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: