Closed
Description
Bug Report
🔎 Search Terms
Generic object inference, Generic object inference based on properties, Generic object inference callback.
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
⏯ Playground Link
💻 Code
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(),
})
🙁 Actual behavior
🙂 Expected behavior
See code comments.