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

--noImplicitOverride #39669

Merged
merged 76 commits into from Mar 26, 2021
Merged

Conversation

Kingwl
Copy link
Contributor

@Kingwl Kingwl commented Jul 20, 2020

Related #38905 , #9034
Fixes #2000

This pr added the override keyword to mark the class method is overrides a method in the base class.
And a flag called noImplicitOverride and don't break something.

Basically, If the flag turns on, We add the below check.

  1. used without noImplicitOverride flag: ok but less check

  2. If a class member has override modifier and the container class does not extend any class: error

  3. if a class member has override modifier and the name of the method is not existed in the base class: error

  4. if a class member do not has override modifier and the name of the method is exited in the base class: error

  5. properties are the same as the method.

  6. node in ambient context: not check.

  7. must before accessibility modifier

  8. cannot be used with the declare static modifier.

  9. cannot be used with a constructor.

Something needs to consider:

  1. class declaration in Ambient context. Should we issue errors in the d.ts files? As Suggestion Backlog Slog, 6/8/2016 #9034 said. Looks needn't.

  2. abstract method or abstract class:

eg:

abstract class AB {
    abstract foo(v: string): void;

    abstract bar(v: string): void
}

abstract class AD1 extends AB {

}

abstract class AD2 extends AB {
    abstract foo(v: ''): void // need override?
}

abstract class AD3 extends AB {
    override foo(v: ''): void { } // need override?
    abstract bar(): void; // need override?
}

class D4 extends AB {
    override foo(v: ''): void {}
    override bar(v: ''): void {}
}
  1. property in constructor parameters:

eg:

class B {
    public baz: number = 1;
    constructor(public foo: string, public bar: number) {

    }
}

class D extends B {
    override public bar: number = 1

    // override required ?
    constructor(public foo: string, public baz: number) {
        super(foo, 42)
    }
}

@Kingwl
Copy link
Contributor Author

Kingwl commented Jul 20, 2020

@typescript-bot run dt.
@typescript-bot pack this.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 20, 2020

The TypeScript team has xxyy

Heya @Kingwl, I've started to run the tarball bundle task on this PR at 37ada55. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 20, 2020

Heya @Kingwl, I've started to run the parallelized Definitely Typed test suite on this PR at 37ada55. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 20, 2020

Hey @Kingwl, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/80234/artifacts?artifactName=tgz&fileId=24EB196251C0700ECE50C8E4EF36FFE41ECC147DC5822099E673D2E05A67AFE302&fileName=/typescript-4.0.0-insiders.20200720.tgz"
    }
}

and then running npm install.


There is also a playground for this build.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jul 21, 2020
@Kingwl Kingwl marked this pull request as ready for review August 19, 2020 03:04
@Kingwl
Copy link
Contributor Author

Kingwl commented Aug 19, 2020

Emmmm.... Need review and feedback

@Kingwl
Copy link
Contributor Author

Kingwl commented Aug 19, 2020

@typescript-bot pack this.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 19, 2020

Heya @Kingwl, I've started to run the tarball bundle task on this PR at 2fd560a. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 19, 2020

Hey @Kingwl, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/82712/artifacts?artifactName=tgz&fileId=F20A5C267D30CCAF558DD8B90945444BF1ECAF2C9D1D3EF7D1AECB09BA31230402&fileName=/typescript-4.1.0-insiders.20200819.tgz"
    }
}

and then running npm install.


There is also a playground for this build.

@Kingwl
Copy link
Contributor Author

Kingwl commented Aug 19, 2020

@typescript-bot pack this.

@DanielRosenwasser
Copy link
Member

Yeah, I doubt we'll see anything significant, and I will likely merge if it's not too crazy seeing as we can optimize later.

@typescript-bot
Copy link
Collaborator

@DanielRosenwasser
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..39669

Metric master 39669 Delta Best Worst
Angular - node (v14.15.1, x64)
Memory used 321,274k (± 0.01%) 321,290k (± 0.01%) +16k (+ 0.01%) 321,215k 321,438k
Parse Time 1.93s (± 0.43%) 1.93s (± 0.61%) -0.00s (- 0.21%) 1.91s 1.96s
Bind Time 0.86s (± 0.57%) 0.85s (± 0.80%) -0.01s (- 1.04%) 0.84s 0.87s
Check Time 5.01s (± 0.46%) 5.01s (± 0.37%) +0.01s (+ 0.14%) 4.96s 5.05s
Emit Time 6.33s (± 0.48%) 6.35s (± 0.63%) +0.03s (+ 0.43%) 6.26s 6.44s
Total Time 14.13s (± 0.28%) 14.15s (± 0.33%) +0.02s (+ 0.12%) 14.07s 14.29s
Compiler-Unions - node (v14.15.1, x64)
Memory used 189,310k (± 0.01%) 189,355k (± 0.01%) +45k (+ 0.02%) 189,314k 189,397k
Parse Time 0.80s (± 0.69%) 0.80s (± 0.87%) -0.00s (- 0.12%) 0.79s 0.82s
Bind Time 0.56s (± 0.40%) 0.56s (± 0.67%) -0.01s (- 1.07%) 0.55s 0.56s
Check Time 7.07s (± 0.59%) 7.03s (± 0.62%) -0.04s (- 0.62%) 6.95s 7.14s
Emit Time 2.54s (± 0.52%) 2.54s (± 0.89%) +0.00s (+ 0.08%) 2.50s 2.60s
Total Time 10.97s (± 0.36%) 10.93s (± 0.54%) -0.05s (- 0.44%) 10.82s 11.08s
Monaco - node (v14.15.1, x64)
Memory used 323,900k (± 0.01%) 323,966k (± 0.01%) +66k (+ 0.02%) 323,941k 324,008k
Parse Time 1.56s (± 0.43%) 1.56s (± 0.82%) -0.00s (- 0.00%) 1.53s 1.58s
Bind Time 0.75s (± 0.80%) 0.75s (± 0.92%) -0.00s (- 0.13%) 0.73s 0.76s
Check Time 5.03s (± 0.54%) 5.02s (± 0.52%) -0.01s (- 0.26%) 4.98s 5.10s
Emit Time 3.18s (± 0.92%) 3.17s (± 0.58%) -0.00s (- 0.16%) 3.13s 3.22s
Total Time 10.52s (± 0.45%) 10.50s (± 0.36%) -0.02s (- 0.16%) 10.42s 10.59s
TFS - node (v14.15.1, x64)
Memory used 287,541k (± 0.01%) 287,629k (± 0.01%) +88k (+ 0.03%) 287,549k 287,673k
Parse Time 1.26s (± 1.13%) 1.25s (± 1.41%) -0.00s (- 0.16%) 1.22s 1.28s
Bind Time 0.72s (± 0.62%) 0.72s (± 0.69%) -0.00s (- 0.28%) 0.71s 0.73s
Check Time 4.65s (± 0.59%) 4.66s (± 0.31%) +0.01s (+ 0.19%) 4.63s 4.69s
Emit Time 3.26s (± 0.71%) 3.26s (± 0.81%) -0.00s (- 0.03%) 3.20s 3.32s
Total Time 9.88s (± 0.42%) 9.89s (± 0.28%) +0.00s (+ 0.05%) 9.83s 9.94s
material-ui - node (v14.15.1, x64)
Memory used 441,841k (± 0.06%) 441,985k (± 0.00%) +144k (+ 0.03%) 441,949k 442,005k
Parse Time 2.07s (± 0.62%) 2.09s (± 0.36%) +0.02s (+ 0.82%) 2.07s 2.10s
Bind Time 0.69s (± 0.69%) 0.69s (± 0.43%) -0.00s (- 0.14%) 0.69s 0.70s
Check Time 13.02s (± 0.60%) 12.91s (± 0.27%) -0.11s (- 0.85%) 12.84s 13.00s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.79s (± 0.53%) 15.69s (± 0.24%) -0.09s (- 0.60%) 15.60s 15.78s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-198-generic
Architecturex64
Available Memory16 GB
Available Memory4 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 39669 10
Baseline master 10

Developer Information:

Download Benchmark

@Kingwl
Copy link
Contributor Author

Kingwl commented Mar 26, 2021

The benchmark looks good, at least with the option off.

PR Backlog automation moved this from Needs review to Needs merge Mar 26, 2021
@DanielRosenwasser DanielRosenwasser merged commit 2f0c8b2 into microsoft:master Mar 26, 2021
PR Backlog automation moved this from Needs merge to Done Mar 26, 2021
@typescript-bot
Copy link
Collaborator

@DanielRosenwasser
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..39669

Metric master 39669 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 344,876k (± 0.02%) 344,936k (± 0.02%) +60k (+ 0.02%) 344,745k 345,113k
Parse Time 1.95s (± 0.55%) 1.93s (± 0.63%) -0.02s (- 1.03%) 1.90s 1.96s
Bind Time 0.84s (± 0.84%) 0.83s (± 0.69%) -0.01s (- 1.07%) 0.82s 0.85s
Check Time 5.09s (± 0.35%) 5.08s (± 0.39%) -0.01s (- 0.16%) 5.04s 5.12s
Emit Time 5.94s (± 0.72%) 5.91s (± 0.60%) -0.03s (- 0.45%) 5.85s 6.00s
Total Time 13.81s (± 0.45%) 13.75s (± 0.31%) -0.06s (- 0.46%) 13.67s 13.86s
Compiler-Unions - node (v10.16.3, x64)
Memory used 203,133k (± 0.12%) 203,224k (± 0.03%) +91k (+ 0.04%) 203,055k 203,325k
Parse Time 0.79s (± 0.87%) 0.78s (± 0.67%) -0.00s (- 0.51%) 0.77s 0.79s
Bind Time 0.53s (± 1.25%) 0.52s (± 1.28%) -0.01s (- 1.89%) 0.51s 0.53s
Check Time 7.55s (± 0.67%) 7.46s (± 0.97%) -0.09s (- 1.23%) 7.32s 7.66s
Emit Time 2.61s (± 1.08%) 2.58s (± 0.99%) -0.04s (- 1.42%) 2.52s 2.62s
Total Time 11.48s (± 0.59%) 11.34s (± 0.77%) -0.14s (- 1.25%) 11.21s 11.59s
Monaco - node (v10.16.3, x64)
Memory used 342,681k (± 0.04%) 342,621k (± 0.02%) -60k (- 0.02%) 342,485k 342,747k
Parse Time 1.56s (± 0.89%) 1.55s (± 0.50%) -0.01s (- 0.64%) 1.53s 1.56s
Bind Time 0.74s (± 0.78%) 0.73s (± 1.21%) -0.01s (- 1.21%) 0.72s 0.76s
Check Time 5.24s (± 0.48%) 5.22s (± 0.51%) -0.01s (- 0.27%) 5.16s 5.28s
Emit Time 3.13s (± 0.31%) 3.12s (± 0.48%) -0.01s (- 0.38%) 3.07s 3.14s
Total Time 10.67s (± 0.35%) 10.63s (± 0.41%) -0.04s (- 0.39%) 10.52s 10.73s
TFS - node (v10.16.3, x64)
Memory used 304,243k (± 0.03%) 304,259k (± 0.03%) +16k (+ 0.01%) 304,028k 304,405k
Parse Time 1.21s (± 0.62%) 1.20s (± 0.74%) -0.01s (- 0.82%) 1.19s 1.23s
Bind Time 0.70s (± 0.68%) 0.70s (± 0.92%) -0.00s (- 0.14%) 0.68s 0.71s
Check Time 4.72s (± 0.59%) 4.71s (± 0.46%) -0.00s (- 0.02%) 4.67s 4.78s
Emit Time 3.27s (± 0.93%) 3.26s (± 1.12%) -0.01s (- 0.28%) 3.17s 3.32s
Total Time 9.90s (± 0.49%) 9.88s (± 0.52%) -0.02s (- 0.23%) 9.77s 10.01s
material-ui - node (v10.16.3, x64)
Memory used 465,477k (± 0.01%) 465,438k (± 0.02%) -39k (- 0.01%) 465,260k 465,623k
Parse Time 2.02s (± 0.55%) 2.01s (± 0.82%) -0.01s (- 0.35%) 1.98s 2.04s
Bind Time 0.66s (± 1.33%) 0.66s (± 0.75%) -0.01s (- 1.06%) 0.65s 0.67s
Check Time 14.32s (± 0.67%) 14.22s (± 0.42%) -0.09s (- 0.64%) 14.13s 14.43s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 17.00s (± 0.59%) 16.89s (± 0.38%) -0.11s (- 0.62%) 16.80s 17.11s
Angular - node (v12.1.0, x64)
Memory used 322,601k (± 0.02%) 322,661k (± 0.03%) +61k (+ 0.02%) 322,488k 322,914k
Parse Time 1.93s (± 0.48%) 1.92s (± 0.82%) -0.01s (- 0.36%) 1.89s 1.96s
Bind Time 0.81s (± 1.02%) 0.82s (± 1.17%) +0.00s (+ 0.12%) 0.80s 0.84s
Check Time 5.01s (± 0.40%) 5.01s (± 0.51%) -0.00s (- 0.02%) 4.97s 5.07s
Emit Time 6.04s (± 0.70%) 5.99s (± 0.67%) -0.05s (- 0.78%) 5.93s 6.10s
Total Time 13.79s (± 0.41%) 13.74s (± 0.43%) -0.05s (- 0.36%) 13.62s 13.89s
Compiler-Unions - node (v12.1.0, x64)
Memory used 190,228k (± 0.23%) 190,215k (± 0.13%) -13k (- 0.01%) 189,506k 190,784k
Parse Time 0.78s (± 0.88%) 0.77s (± 0.86%) -0.00s (- 0.26%) 0.76s 0.79s
Bind Time 0.53s (± 0.63%) 0.53s (± 0.76%) -0.00s (- 0.19%) 0.52s 0.54s
Check Time 7.04s (± 0.75%) 6.96s (± 0.45%) -0.07s (- 1.04%) 6.88s 7.05s
Emit Time 2.56s (± 1.02%) 2.56s (± 1.09%) +0.00s (+ 0.08%) 2.50s 2.61s
Total Time 10.90s (± 0.61%) 10.83s (± 0.32%) -0.07s (- 0.66%) 10.76s 10.90s
Monaco - node (v12.1.0, x64)
Memory used 325,000k (± 0.02%) 325,039k (± 0.02%) +39k (+ 0.01%) 324,848k 325,174k
Parse Time 1.54s (± 0.61%) 1.53s (± 0.87%) -0.01s (- 0.84%) 1.51s 1.57s
Bind Time 0.72s (± 0.80%) 0.72s (± 0.41%) -0.01s (- 0.69%) 0.71s 0.72s
Check Time 5.09s (± 0.70%) 5.08s (± 0.67%) -0.01s (- 0.14%) 5.03s 5.14s
Emit Time 3.14s (± 0.78%) 3.11s (± 0.74%) -0.03s (- 0.86%) 3.07s 3.17s
Total Time 10.49s (± 0.60%) 10.44s (± 0.53%) -0.05s (- 0.48%) 10.34s 10.58s
TFS - node (v12.1.0, x64)
Memory used 288,703k (± 0.02%) 288,748k (± 0.02%) +46k (+ 0.02%) 288,655k 288,904k
Parse Time 1.21s (± 0.43%) 1.20s (± 1.00%) -0.01s (- 0.41%) 1.17s 1.23s
Bind Time 0.70s (± 1.28%) 0.69s (± 0.75%) -0.01s (- 1.01%) 0.68s 0.70s
Check Time 4.65s (± 0.50%) 4.63s (± 0.38%) -0.02s (- 0.39%) 4.59s 4.67s
Emit Time 3.18s (± 0.66%) 3.17s (± 0.98%) -0.00s (- 0.13%) 3.11s 3.25s
Total Time 9.72s (± 0.41%) 9.69s (± 0.49%) -0.03s (- 0.33%) 9.59s 9.81s
material-ui - node (v12.1.0, x64)
Memory used 443,647k (± 0.01%) 443,544k (± 0.05%) -103k (- 0.02%) 442,584k 443,743k
Parse Time 2.04s (± 0.54%) 2.03s (± 0.45%) -0.01s (- 0.44%) 2.01s 2.05s
Bind Time 0.65s (± 1.05%) 0.64s (± 0.73%) -0.01s (- 0.93%) 0.63s 0.65s
Check Time 12.88s (± 0.56%) 12.90s (± 0.72%) +0.02s (+ 0.12%) 12.76s 13.11s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.57s (± 0.51%) 15.57s (± 0.65%) +0.00s (+ 0.02%) 15.42s 15.81s
Angular - node (v14.15.1, x64)
Memory used 321,274k (± 0.01%) 321,302k (± 0.01%) +28k (+ 0.01%) 321,198k 321,351k
Parse Time 1.93s (± 0.43%) 1.92s (± 0.46%) -0.01s (- 0.62%) 1.91s 1.95s
Bind Time 0.86s (± 0.57%) 0.86s (± 0.61%) -0.01s (- 0.58%) 0.84s 0.87s
Check Time 5.01s (± 0.46%) 5.00s (± 0.49%) -0.01s (- 0.10%) 4.95s 5.05s
Emit Time 6.33s (± 0.48%) 6.31s (± 0.52%) -0.02s (- 0.32%) 6.21s 6.35s
Total Time 14.13s (± 0.28%) 14.09s (± 0.37%) -0.04s (- 0.30%) 13.99s 14.20s
Compiler-Unions - node (v14.15.1, x64)
Memory used 189,310k (± 0.01%) 189,366k (± 0.01%) +57k (+ 0.03%) 189,333k 189,412k
Parse Time 0.80s (± 0.69%) 0.79s (± 0.63%) -0.01s (- 0.87%) 0.79s 0.81s
Bind Time 0.56s (± 0.40%) 0.55s (± 0.67%) -0.01s (- 1.07%) 0.55s 0.56s
Check Time 7.07s (± 0.59%) 7.06s (± 0.48%) -0.01s (- 0.11%) 7.01s 7.16s
Emit Time 2.54s (± 0.52%) 2.54s (± 0.41%) +0.00s (+ 0.00%) 2.51s 2.56s
Total Time 10.97s (± 0.36%) 10.95s (± 0.35%) -0.02s (- 0.19%) 10.88s 11.05s
Monaco - node (v14.15.1, x64)
Memory used 323,900k (± 0.01%) 323,953k (± 0.01%) +53k (+ 0.02%) 323,905k 324,010k
Parse Time 1.56s (± 0.43%) 1.56s (± 0.70%) -0.00s (- 0.13%) 1.54s 1.59s
Bind Time 0.75s (± 0.80%) 0.74s (± 0.66%) -0.00s (- 0.27%) 0.74s 0.76s
Check Time 5.03s (± 0.54%) 5.03s (± 0.44%) +0.00s (+ 0.02%) 4.98s 5.09s
Emit Time 3.18s (± 0.92%) 3.16s (± 0.39%) -0.02s (- 0.69%) 3.13s 3.19s
Total Time 10.52s (± 0.45%) 10.49s (± 0.26%) -0.03s (- 0.28%) 10.43s 10.56s
TFS - node (v14.15.1, x64)
Memory used 287,541k (± 0.01%) 287,632k (± 0.01%) +92k (+ 0.03%) 287,559k 287,674k
Parse Time 1.26s (± 1.13%) 1.24s (± 0.91%) -0.01s (- 1.19%) 1.22s 1.26s
Bind Time 0.72s (± 0.62%) 0.72s (± 1.49%) +0.00s (+ 0.14%) 0.71s 0.76s
Check Time 4.65s (± 0.59%) 4.64s (± 0.51%) -0.00s (- 0.04%) 4.59s 4.69s
Emit Time 3.26s (± 0.71%) 3.26s (± 0.70%) -0.01s (- 0.21%) 3.19s 3.30s
Total Time 9.88s (± 0.42%) 9.86s (± 0.39%) -0.02s (- 0.23%) 9.76s 9.92s
material-ui - node (v14.15.1, x64)
Memory used 441,841k (± 0.06%) 441,994k (± 0.00%) +154k (+ 0.03%) 441,971k 442,021k
Parse Time 2.07s (± 0.62%) 2.09s (± 0.52%) +0.02s (+ 1.06%) 2.07s 2.11s
Bind Time 0.69s (± 0.69%) 0.69s (± 0.43%) -0.00s (- 0.14%) 0.69s 0.70s
Check Time 13.02s (± 0.60%) 12.98s (± 0.47%) -0.04s (- 0.31%) 12.90s 13.12s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.79s (± 0.53%) 15.76s (± 0.42%) -0.02s (- 0.13%) 15.66s 15.91s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-198-generic
Architecturex64
Available Memory16 GB
Available Memory4 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 39669 10
Baseline master 10

Developer Information:

Download Benchmark

@Jack-Works
Copy link
Contributor

https://www.typescriptlang.org/play?ts=4.3.0-dev.20210406#code/MYGwhgzhAECK0G8CwAoa7oE8AUBKRAvqkSqJDACrQCmAHgC7UB2AJjPMmhgPYBu1AJwEBLFtSx5CxVEA

Is this expected? For code

class Q {
    y() {}
}
class T extends Q {
    override y() {}
}

The nightly playground emits the following JS code

"use strict";
class Q {
    y() { }
}
class T extends Q {
    override y() { }
}

which IMO is invalid. Is override y() {} a valid JS class member?

@Kingwl
Copy link
Contributor Author

Kingwl commented Apr 7, 2021

@Jack-Works Nope. Fixed in #43536.

@danfma
Copy link

danfma commented Apr 23, 2021

The compiler is complaining about the missing override keyword for constructor declared properties but it doesn't allow using the modifier on the constructor too.

@andrewbranch
Copy link
Member

@danfma can you give an example?

@danfma
Copy link

danfma commented Apr 23, 2021

Yes.

On the left side, it's the original code. So, I tried to put the override in the constructor like protected override readonly context... the compiler will complain.

We had to use like in the right side to force the compiler to accept the code.

image

@Kingwl
Copy link
Contributor Author

Kingwl commented Apr 24, 2021

Would we consider to add quickfix for parameter property or allow override in parameter property as @danfma said.😂

@danfma
Copy link

danfma commented Apr 24, 2021

By the way, this language feature fits me very well because I'm using an AST transformer to apply some Mobx decorators, and one of these modifiers is the “override” decorator! So, I can read the modifier and translate the code to what Mobx needs!

Thus, thank you! 😬

@andrewbranch
Copy link
Member

@Kingwl I think we’re going to allow override in the parameter property, but I’m going to run it by the design meeting on Wednesday.

@Kingwl
Copy link
Contributor Author

Kingwl commented Apr 26, 2021

Okay. Looking forward for the good news :XP

@jogibear9988
Copy link

I've problems with static fields and override: #43916

@SLaks
Copy link

SLaks commented Jun 8, 2021

What about methods that implement interface (as opposed to base class) members?

@Kingwl
Copy link
Contributor Author

Kingwl commented Jun 9, 2021

What about methods that implement interface (as opposed to base class) members?

No plan yet.

@guilhermesimoes
Copy link

Is there a way to apply this to my entire project except to classes that inherit from a particular class (like React.Component, for example)?

@ekilah
Copy link

ekilah commented Jun 29, 2023

Same question/need as @guilhermesimoes - getting errors on state and render inside a React.Component is not helpful, but this flag would be very helpful outside of React (class) components.

without a way to exclude these (either by name, e.g. state, render, componentDidMount, etc.), or specifically for known React class properties (exceptReact or something), or even maybe include/exclude by directory or file extension (e.g. *.ts but not *.tsx), i can't use --noImplicitOverride in my project, but I have lots of non-React classes I'd love to have this protection apply to.

I realize that the TS team is not likely to want to have React-specific things in its codebase, but I just wanted to bring more attention to a common pain point with this feature for a subset of your users :)


Example errors for reference:

ERROR in src/SomeComponent/index.tsx:22:3
TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Component<IProps, IState, any>'.
    20 |   IState
    21 | > {
  > 22 |   state: IState = {}
       |   ^^^^^
    23 |
    24 |   render() {

ERROR in src/SomeComponent/index.tsx:24:3
TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Component<IProps, IState, any>'.
    22 |   state: IState = {}
    23 |
  > 24 |   render() {
       |   ^^^^^^
    25 |     return (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

Support override keyword on class methods