You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The override keyword does not change runtime behavior but can help programmers in a few ways:
When reading code, it alerts you that a method is overriding one from the base class
It is an error to try to override a method that does not exist on the base class. This can help catch errors caused by renaming a method in a base class but forgetting to update the method name in the subclasses.
Enabling
I propose enabling this new flag for both VS Code code and extensions.
Enabling it currently causes ~2200 compile errors, however unlike the previous strictness checks we enabled, I believe should simply use a script to automatically fix the vast majority of them (by inserting override in the necessary location)
Reacted by Daniel Imms, Peng Lyu, Benjamin Pasero, Johannes Rieken and Connor Peet
Hooking up individual quick fixes would be a little more difficult but should be doable (writing a simple python find/replace script was a lot quicker in this case)
Johannes Rieken (@jrieken)Alexandru Dima (@alexdima) Do you have any idea about why MirrorModel.version is causing issues with the esm build? After adding override to version, yarn gulp editor-esm-bundle results in:
Launching the TS compiler at /Users/matb/projects/vscode/out-editor-esm...
vs/editor/common/services/editorSimpleWorker.ts(94,22): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'MirrorTextModel'.
In our source, MirrorTextModel has a property:
getversion(): number {returnthis._versionId;}
However in the esm build, this property is missing from MirrorTextModel . It may be getting removed by our tree shaking
Do you have any idea about why MirrorModel.version is causing issues with the esm build?
Yes, TypeScript is sometimes incorrect when invoking Find all references and this was one of those cases, where finding all references on ICommonModel.version would not return MirrorTextModel.version. As far as I am concerned, this is a TypeScript bug that also manifests itself when doing a rename. For example, renaming ICommonModel.version to ICommonModel.versionX will introduce a compilation error. I have reported the problem to TS, but the issue was closed microsoft/TypeScript#25831
To resolve the problem, I added another interface and an explicit implements ... heritage clause to help TS find all references correctly.
Activity
Pick up new TS 4.3
mjbvz commentedon Apr 7, 2021
Here's the simple python script I used to automate most of the rewrites:
This is a pretty simple script but takes us from 2200 errors to 200 or so.
The remaining errors fall into a few buckets:
Cases where the property is declared in a constructor.
Many of these seem to be errors (such as a subclass re-declaring a protected property)
The rest need to be re-written manually
declare readonly _serviceBrand: undefinedProperty using
declareprompts to add 'override' even though that does not seem valid TypeScript#43566We should likely just change these to
override readonly _serviceBrand: undefinedStatic properties overriding non-static property
noImplicitOverride complains about static property not overriding non-static property TypeScript#43563
Seems to be a bug on the TS side
Kingwl commentedon Apr 7, 2021
Cool! But... Are there any tools could batch apply quickfix?
Build with latest TS nightly (#120690)
mjbvz commentedon Apr 7, 2021
Wenlu Wang (@Kingwl) Not that I know off. For source actions, you can use https://marketplace.visualstudio.com/items?itemName=bierner.folder-source-actions
Hooking up individual quick fixes would be a little more difficult but should be doable (writing a simple python find/replace script was a lot quicker in this case)
32 remaining items
enable noImplicitOverride in our codebase
Adding a few more override specifiers
mjbvz commentedon Apr 20, 2021
Alexandru Dima (@alexdima) SteVen Batten (@sbatten) Just 6 errors remaining! Please take a look when you have a chance
Johannes Rieken (@jrieken) Alexandru Dima (@alexdima) Do you have any idea about why
MirrorModel.versionis causing issues with the esm build? After addingoverridetoversion,yarn gulp editor-esm-bundleresults in:In our source,
MirrorTextModelhas a property:However in the
esmbuild, this property is missing fromMirrorTextModel. It may be getting removed by our tree shakingFix `--noImplicitOverride` problems (#120675)
alexdima commentedon Apr 22, 2021
Yes, TypeScript is sometimes incorrect when invoking Find all references and this was one of those cases, where finding all references on
ICommonModel.versionwould not returnMirrorTextModel.version. As far as I am concerned, this is a TypeScript bug that also manifests itself when doing a rename. For example, renamingICommonModel.versiontoICommonModel.versionXwill introduce a compilation error. I have reported the problem to TS, but the issue was closed microsoft/TypeScript#25831To resolve the problem, I added another interface and an explicit
implements ...heritage clause to help TS find all references correctly.refs #120675
mjbvz commentedon Apr 24, 2021
Done with 66fd0cb
Thanks everyone!