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

Quickinfo incorrectly computes zero-candidate type parameter with contextual inference candidate #44879

Closed
devanshj opened this issue Jul 3, 2021 · 2 comments Β· Fixed by #52146
Labels
Bug A bug in TypeScript Domain: Quick Info e.g. hover text, tool-tips, and tooltips.
Milestone

Comments

@devanshj
Copy link

devanshj commented Jul 3, 2021

Bug Report

πŸ”Ž Search Terms

intellisense, contextual inference, call site inference
Related: #44821

πŸ•— Version & Regression Information

Tested with v4.3.4

⏯ Playground Link

Playground

πŸ’» Code

m({ foo: $("foo") }); // unexpected error

declare const m:
  <S extends string>(s: { [_ in S]: { $: NoInfer<S> } }) => void

declare const $: <S, T extends S>(s: T) =>
  { $: S }

type NoInfer<T> = [T][T extends any ? 0 : never];

πŸ™ Actual behavior

Code does not compile

πŸ™‚ Expected behavior

Code should compile. Especially when the intellisense gets the type parameters right and also provides completions.

Expected type parameters and return type -

Expected completion -

But doesn't compile and gives error -

@RyanCavanaugh RyanCavanaugh changed the title Probable bug: Inconsistency between compilation and intellisense in case of contextual inference at call-site Quickinfo incorrectly computes zero-candidate type parameter with contextual inference candidate Jul 6, 2021
@RyanCavanaugh
Copy link
Member

The compile-time inference is correct. I'm not sure what $ is trying to accomplish, but it's not written in a way that can produce meaningful results -- it says "I take a T and return some supertype of that in $", which doesn't really make any sense.

@devanshj
Copy link
Author

devanshj commented Jul 7, 2021

Yeah it was sort of a workaround, it should have simply been $: <T>(s: T) => { $: T } (the $1 version) as you said here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Quick Info e.g. hover text, tool-tips, and tooltips.
Projects
None yet
2 participants