Skip to content

Support ECMAScript private fields added from TS 3.8#157

Merged
HerringtonDarkholme merged 1 commit into
HerringtonDarkholme:masterfrom
rhysd:private-field
Jan 11, 2020
Merged

Support ECMAScript private fields added from TS 3.8#157
HerringtonDarkholme merged 1 commit into
HerringtonDarkholme:masterfrom
rhysd:private-field

Conversation

@rhysd
Copy link
Copy Markdown
Contributor

@rhysd rhysd commented Jan 11, 2020

ECMAScript private fields spec was implemented in TypeScript and released at v3.8 beta.

microsoft/TypeScript#33925

class C {
    #foo = 10;
    bar = true;

    piyo() {
        return this.#foo;
    }
}
  • Previously the private name field declaration #foo in #foo = 10 was not highlighted. This PR adds highlight to it
  • Now '#' is part of identifiers in TypeScript. So this PR adds it to iskeyword option. Vim can recognize #foo as one identifier by it.

@HerringtonDarkholme
Copy link
Copy Markdown
Owner

Thanks!

@HerringtonDarkholme HerringtonDarkholme merged commit 81137eb into HerringtonDarkholme:master Jan 11, 2020
@NullVoxPopuli
Copy link
Copy Markdown

are private methods a thing?

@rhysd
Copy link
Copy Markdown
Contributor Author

rhysd commented Feb 8, 2020

I did not care methods.

@rhysd
Copy link
Copy Markdown
Contributor Author

rhysd commented Feb 9, 2020

I checked TypeScript 3.8 RC, but it does not support private methods. It's private 'fields' so it does not include methods.

I tried:

class Foo {
    #foo() {
        console.log('hi');
    }
    show() {
        this.#foo();
    }
}

and I got:

foo.ts:2:5 - error TS18022: A method cannot be named with a private identifier.

2     #foo() {
      ~~~~


Found 1 error.

@HerringtonDarkholme
Copy link
Copy Markdown
Owner

Hi @NullVoxPopuli, it won't be hard to add private method support once it is available in TypeScript.
Let's wait for its adoption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants