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 for contextually typed arrow function parameter can be incorrect #21382

Closed
weswigham opened this issue Jan 24, 2018 · 2 comments
Closed
Labels
Bug A bug in TypeScript Domain: Quick Info e.g. hover text, tool-tips, and tooltips. Fixed A PR has been merged for this issue

Comments

@weswigham
Copy link
Member

TypeScript Version: 2.7.0-dev.201xxxxx

Search Terms:

Code

interface BaseProps<T> {
  initialValues: T;
  nextValues: (cur: T) => T;
}
declare class Component<P> { constructor(props: P); props: P; }
declare class GenericComponent<Props = {}, Values = object>
    extends Component<Props & BaseProps<Values>> {
  iv: Values;
}

new GenericComponent({ initialValues: 12, nextValues: val => 12 });

Expected behavior:
Hover over val - see number. (Also: type val. in the lambda body and trigger completions, get completions for numbers). Hover over nextValues, see (val: number) => number.

Actual behavior:
val's quick info is any (compilation and errors show it is assigned the correct type during compilation, the quick info on GenericComponent is thankfully correct), has no completions (being any), and nextValues has a quickinfo type of (cur: number) => number & (val: number) => number, which is an intersection of two conspicuously identical signatures.

Playground Link (Also, here's a fourslash test to start anyone working on this off)

Preliminary investigation (read: believing this bug was related to JSX before trying the same construct outside a JSX tag) led me to believe this has something to do with execution order, as inference statefully assigns types to symbols via assignTypeToParameterAndFixTypeParameters, meaning if inference happens it assigns a type to the symbol, whereas if that hasn't happened and there's no cached type from an inference triggered by a check call, quickinfo only finds the contextual type for the position. However requesting errors (which does a full typecheck) prior to checking quickinfo doesn't hide the error (which would be expected if the issue depended on execution order), so I'm unsure what the underlying problem is. The correct types are returned at these positions for our .types baselines by getTypeAtLocation, which, in these cases, is just a roundabout way to say getTypeOfSymbol on the node's symbol, which is the same as getTypeOfSymbolAtLocation in these locations (which is what's used in services).

@sandersn
Copy link
Member

Doesn’t sound like there is any order-dependent behaviour here (if I read your description right), so I guess it makes sense that the implementation wouldn’t have an order-dependent bug.

@weswigham
Copy link
Member Author

Well, differing results between .types baselines and quickinfo can be caused by order dependence, but I don't think it's the case here, since guaranteeing a full typechecked before fetching quickinfo doesn't suppress the issue.

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. Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants