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

Hover type definition is wrongly inferred, but tsc type is correct #26577

Closed
hf opened this issue Aug 21, 2018 · 3 comments
Closed

Hover type definition is wrongly inferred, but tsc type is correct #26577

hf opened this issue Aug 21, 2018 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@hf
Copy link

hf commented Aug 21, 2018

There's a small but annoying issue in the tsserver implementation (as far as I can tell) that's been around for a long time, I'm tracking from version 2.6.

Namely, there is a mapped-type pattern I want to use, as shown in code below, and the hover type definition doesn't infer multiple levels deep. However, interestingly, tsc does infer the type correctly.

TypeScript Version: 2.6+

Code

type F<T> = (value: any) => T

function all<V>(vals: { [K in keyof V]: F<V[K]> }): (value: any) => V {
    return null as any;
}

// inspect the hover type of `x`
// it should show const x: { a: { b: any } }
const x = all({
    a: all({
        b: (value: any) => 3
    })
})(3)

// inspect the hover type of `b`
// it should show (property) b: number
x.a.b;

// and obviously this does not compile
x.a.b = 'not-a-number';

Expected behavior:

The hover type definition (and it's variants) should show

const x: { a: { b: number } }

Actual behavior:

The hover type definition for x is

const x: { a: { b: any } }

Playground Link

Related Issues: Not that I found.

@hf
Copy link
Author

hf commented Aug 21, 2018

By "hover type definition" I mean the type definition shown by the editor (any which uses tsserver) when you "hover" over a symbol.

@RyanCavanaugh
Copy link
Member

Duplicate #23897

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 21, 2018
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants