Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic inference issue with callbacks #48009

Closed
sampbarrow opened this issue Feb 23, 2022 · 2 comments
Closed

Generic inference issue with callbacks #48009

sampbarrow opened this issue Feb 23, 2022 · 2 comments
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@sampbarrow
Copy link

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

https://www.typescriptlang.org/play?#code/FAFwngDgpgBAwgewLYCMEB4DqCBOBrAZwBoYARBKAgOxG3wD4YBeGAb2AEgRKQBGALhgAKAJTNGdQp24EQAJkFCAbgEMANgFcog2TgCWVAOZimjcpRqTOAMw1UAxgOGrN2mJIInGug4Zt37BWd1LUFzalpcPC8YHyNgAF9gezUVAgJ4ZDQ4VPT0ABUSADVGdg57BCpdDXsQXCEcKBUAE0q1MBhmqGsDPRA9SsFEVAxCmBKxMqSkgHoZ8KoAchAYAHco5MrZGAqR3mYYKihVzJGctIIhMpk+RRjeImkeIOUQqBi5R45bBycXLXEMH+UAAdHUADIIezqKAAZRA+iMoi+P0CgmBgOBYIQkOhajhCN8yLmAFEAEpkgDyZJgAFogW8YHoMghrDBwNAYHY8FQEKsqIkRMA5h5NlUVrs0HIDkcTsNsrlLtceE5RICHk9ZC9gTpCUYPiQ5gBJGAACxUSlgdVi0HsemsHR1sT1hjpMCglqo7NNCA0hlNTJAiwyvJWhigR309jdfWDMHUqxUYAycVdKiozW9sF2ED0+JwMB5fIyfTWfVNBm9zJgqP6lXdnqZbJNrSWKwItvtHT6IP8v3RjNMDNc2NxMPhiMMyL7aOHAKHWIhUPHLunCSFQA

💻 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.

@RyanCavanaugh RyanCavanaugh added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Feb 23, 2022
@RyanCavanaugh
Copy link
Member

TypeScript doesn't do multiple "rounds" of inference as would be required here. See #30134

@jcalz
Copy link
Contributor

jcalz commented Oct 9, 2022

Fixed by #48538, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

3 participants