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
type Combo<Works, DoesntWork> = {
test1: () => Works
test2: (value: string) => DoesntWork
func1: (value: Works) => string
func2: (value: DoesntWork) => string
}
class ComboClass<T, V> {
constructor(readonly definition: Combo<T, V>) {
}
}
//Doesn't work
const combo1 = new ComboClass({
test1: () => 1,
test2: (value) => 2,
func1: value => value.toLocaleString(),
func2: value => value.toLocaleString(),//ERROR - value is of type unknown
})
//Works
const combo2 = new ComboClass({
test1: () => 1,
test2: (value: string) => 2, //I have to specify value: string - even though it's not generic - it's always string. Within this function, the compiler knows it's a string, but it breaks the inference for some reason.
func1: value => value.toLocaleString(),
func2: value => value.toLocaleString(),
})
Activity
RyanCavanaugh commentedon Feb 23, 2022
TypeScript doesn't do multiple "rounds" of inference as would be required here. See #30134
jcalz commentedon Oct 9, 2022
Fixed by #48538, right?