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(),
})
🙁 Actual behavior
🙂 Expected behavior
See code comments.
The text was updated successfully, but these errors were encountered:
Bug Report
🔎 Search Terms
Generic object inference, Generic object inference based on properties, Generic object inference callback.
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?#code/FAFwngDgpgBAwgewLYCMEB4DqCBOBrAZwBoYARBKAgOxG3wD4YBeGAb2AEgRKQBGALhgAKAJTNGdQp24EQAJkFCAbgEMANgFcog2TgCWVAOZimjcpRqTOAMw1UAxgOGrN2mJIInGug4Zt37BWd1LUFzalpcPC8YHyNgAF9gezUVAgJ4ZDQ4VPT0ABUSADVGdg57BCpdDXsQXCEcKBUAE0q1MBhmqGsDPRA9SsFEVAxCmBKxMqSkgHoZ8KoAchAYAHco5MrZGAqR3mYYKihVzJGctIIhMpk+RRjeImkeIOUQqBi5R45bBycXLXEMH+UAAdHUADIIezqKAAZRA+iMoi+P0CgmBgOBYIQkOhajhCN8yLmAFEAEpkgDyZJgAFogW8YHoMghrDBwNAYHY8FQEKsqIkRMA5h5NlUVrs0HIDkcTsNsrlLtceE5RICHk9ZC9gTpCUYPiQ5gBJGAACxUSlgdVi0HsemsHR1sT1hjpMCglqo7NNCA0hlNTJAiwyvJWhigR309jdfWDMHUqxUYAycVdKiozW9sF2ED0+JwMB5fIyfTWfVNBm9zJgqP6lXdnqZbJNrSWKwItvtHT6IP8v3RjNMDNc2NxMPhiMMyL7aOHAKHWIhUPHLunCSFQA
💻 Code
🙁 Actual behavior
🙂 Expected behavior
See code comments.
The text was updated successfully, but these errors were encountered: