orta / vscode-twoslash-queries

VS Code extension which adds support for twoslash queries into typescript projects
https://marketplace.visualstudio.com/items?itemName=Orta.vscode-twoslash-queries
MIT License
419 stars 15 forks source link

Incorrect types is reported when there is no new line between types #28

Closed scottwillmoore closed 1 year ago

scottwillmoore commented 1 year ago

I just installed the extension, but it doesn't appear to show the correct type when there are no new lines between types.

In this example, the wrong type is displayed next to each of the types.

type IsNumber<T> = T extends number ? true : false;

type A = IsNumber<undefined>; // => type A = false
type B = IsNumber<null>; // => type A = false
type C = IsNumber<number>; // => type B = false
//   ^? type B = false
type D = IsNumber<number | string>; // => type D = boolean
type E = IsNumber<0>; // => type D = boolean
type F = IsNumber<0 | 1>; // => type E = boolean
type G = IsNumber<0 | "0">; // => type F = boolean

However, when new lines are added the issue is resolved.

type IsNumber<T> = T extends number ? true : false;

type A = IsNumber<undefined>; // => type A = false

type B = IsNumber<null>; // => type B = false

type C = IsNumber<number>; // => type C = true
//   ^?
type D = IsNumber<number | string>; // => type D = boolean

type E = IsNumber<0>; // => type E = true

type F = IsNumber<0 | 1>; // => type F = true

type G = IsNumber<0 | "0">; // => type G = boolean

TypeScript version: 5.1.3. Visual Studio Code version: 1.79.2. Extension version: 1.2.0.

I have inlay hints shown when I hold Ctrl + Alt.

EDIT(1): Shouldn't the TypeScript language server implement inlay hints for type definitions. I couldn't find an option in my Visual Studio Code settings, and I couldn't find any relevant issues on the TypeScript repository. I guess I should raise my own issue?

EDIT(2): To clarify, I did find your issue to upstream this extension. However, couldn't TypeScript just support type A /* = false */ = IsNumber<undefined>; in a similar manner that it works for parameters, variables, etc. The twoslash query is not required, but could still be provided by this extension.

ssalbdivad commented 1 year ago

@orta This seems to have been a regression in version 1.2.0.

Previously //^? comments worked as expected in VSCode in WSL Ubuntu.

After, I'm seeing a lot of incorrect results that seem to be the same root cause as those @scottwillmoore described. I'm confused about all the inlay hints stuff as that seems unrelated to me, but this version does seem to be broken at the moment.

orta commented 1 year ago

Yeah, this seems like a bug with the lookup code changes in https://github.com/orta/vscode-twoslash-queries/pull/23 to me 👍🏻