Repository navigation
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
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.
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
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?