-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Description
π Search Terms
"template string", "default value", "infer type", "destructuring"
π Version & Regression Information
This changed between versions 5.1.6
and 5.2.2
. The bug is also present in 5.3.0-dev.20230928
.
β― Playground Link
π» Code
type Params = {
value?: string | number
}
function example(parameters: Params) {
const { value = '123' } = parameters
return `${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
digitalhank
Metadata
Metadata
Assignees
Labels
No labels