Closed
Description
Bug Report
π Search Terms
Implicit conversion symbol fail runtime
π Version & Regression Information
- This changed between versions 4.6.* and 4.7.*
β― Playground Link
Playground link with relevant code
π» Code
interface Property<T> {
name: keyof T
}
interface ThingA {
a: string
b: string
}
interface ThingB {
c: string
d: string
}
function Filter<T extends ThingA | ThingB>(properties: Property<T>[]) {
return properties.map((property) => `input-${property.name}`) // <-- Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'.(2731)
}
π Actual behavior
Typescript thinks that property.name
here may be a Symbol. I guess maybe this makes sense since T extends ThingA | ThingB
wouldn't prohibit a ThingC
interface that extends ThingA with a symbol property. But I'd expect this new error to pop up in a lot more places in my codebase, but I only see it in this one spot.
I'm not sure in what circumstances this error is triggered, or how to work around it. I'd rather not add String(...)
around the property because that's unnecessary extra runtime code.
π Expected behavior
Because this doesn't fail in TS < 4.7, I'd expect it not to suddenly start failing.