Skip to content

this and typeof are not type keywords in completions #32486

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

Open
sandersn opened this issue Jul 19, 2019 · 5 comments
Open

this and typeof are not type keywords in completions #32486

sandersn opened this issue Jul 19, 2019 · 5 comments
Assignees
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Help Wanted You can do this
Milestone

Comments

@sandersn
Copy link
Member

In services/utilities.ts:1213, this and typeof are not in

    export const typeKeywords: ReadonlyArray<SyntaxKind> = [
        SyntaxKind.AnyKeyword,
        SyntaxKind.BigIntKeyword,
        SyntaxKind.BooleanKeyword,
        SyntaxKind.FalseKeyword,
        SyntaxKind.KeyOfKeyword,
        SyntaxKind.NeverKeyword,
        SyntaxKind.NullKeyword,
        SyntaxKind.NumberKeyword,
        SyntaxKind.ObjectKeyword,
        SyntaxKind.ReadonlyKeyword,
        SyntaxKind.StringKeyword,
        SyntaxKind.SymbolKeyword,
        SyntaxKind.TrueKeyword,
        SyntaxKind.VoidKeyword,
        SyntaxKind.UndefinedKeyword,
        SyntaxKind.UniqueKeyword,
        SyntaxKind.UnknownKeyword,
    ];

even though they are type keywords. Unfortunately, adding them breaks some tests to do with find-all-refs with global this -- patterns like function f(this) { this } start identifying the this inside the function as the global this.

@sandersn sandersn added the Bug A bug in TypeScript label Jul 19, 2019
@sandersn sandersn added this to the Backlog milestone Jul 19, 2019
@fatcerberus
Copy link

function f(this) { this }

Isn’t this a syntax error?

@sandersn
Copy link
Member Author

In JS yes, in TS no. TS allows the first parameter to be this in order to specify the type of this inside the function.

@fatcerberus
Copy link

Ah right - I knew about the this parameter but didn’t make the connection since that would be an automatic noImplicitAny error - not used to seeing bare parameters anymore 😃

@jakebailey
Copy link
Member

This was half-fixed in #53325, but things do still fail as described if you just add ThisKeyword without other changes.

@gabritto
Copy link
Member

Noticed this today and it is very annoying to be typing this in a type position and pressing a commit character, only to see some global type accepted as completion, e.g:

interface Foo {
        foo(): this|
}

if you then press ;, which is a commit character, we autocomplete with some type:

interface F {
        foo(): ThisParameterType;
}

@gabritto gabritto added Help Wanted You can do this Domain: Completion Lists The issue relates to showing completion lists in an editor labels Aug 13, 2024
@gabritto gabritto self-assigned this Aug 13, 2024
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: Completion Lists The issue relates to showing completion lists in an editor Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

4 participants