-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Enable noImplicitOverride in our codebase #120675
Comments
Also tests adding override keywords for extensions as part of microsoft#120675
Here's the simple python script I used to automate most of the rewrites: from os import path
import re
def fixThisMember(file, line, col):
with open(file, 'r') as f:
lines = f.readlines()
lineContent = lines[line - 1]
# public? async? method(
lineContent = re.sub(
r'^(\s+)((?:public|private|protected) )?(async )?([\w_$]+[\(<])',
r'\1\2\3override \4',
lineContent)
# public? get|set prop(
lineContent = re.sub(
r'^(\s+)((?:public|private|protected) )?(get|set) ([\w_$]+)\(',
r'\1\2override \3 \4(',
lineContent)
# public? readonly? prop =
lineContent = re.sub(
r'^(\s+)((?:public|private|protected) )?(readonly )?([\w_$]+) =',
r'\1\2\3override \4 =',
lineContent)
# public? readonly? prop:
lineContent = re.sub(
r'^(\s+)((?:public|private|protected) )?(readonly )?([\w_$]+):',
r'\1\2\3override \4:',
lineContent)
if lineContent != lines[line - 1]:
print(file)
lines[line - 1] = lineContent
with open(file, 'w') as f:
f.writelines(lines)
# file containing `yarn watch` error text
with open('override-errors.text') as f:
for line in f:
pMatch = re.match(r'.+Error: (.+)\((\d+),(\d+)\): (This member must have an)',
line, flags=re.I)
if pMatch:
file = pMatch.group(1)
line = int(pMatch.group(2))
col = int(pMatch.group(3))
fixThisMember(file, line, col) This is a pretty simple script but takes us from 2200 errors to 200 or so. The remaining errors fall into a few buckets:
|
Cool! But... Are there any tools could batch apply quickfix? |
* Pick up new TS 4.3 Also tests adding override keywords for extensions as part of #120675 * Update to daily TS and workaround TS 4.3 issue Works around microsoft/TypeScript#43578
For microsoft#120675 This uses a script to add the `override` keyword to places that need it in the codebase
@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) |
* Pick up new TS 4.3 Also tests adding override keywords for extensions as part of #120675 * Update to daily TS and workaround TS 4.3 issue Works around microsoft/TypeScript#43578
For microsoft#120675 This uses a script to add the override keyword to places that need it in the codebase Note that we can't enable the --noImplicitOverride setting yet since there are still around 200 errors that require further attention
For microsoft#120675 This uses a script to add the override keyword to places that need it in the codebase Note that we can't enable the --noImplicitOverride setting yet since there are still around 200 errors that require further attention
For microsoft#120675 This uses a script to add the override keyword to places that need it in the codebase Note that we can't enable the --noImplicitOverride setting yet since there are still around 200 errors that require further attention
For #120675 This uses a script to add the override keyword to places that need it in the codebase Note that we can't enable the --noImplicitOverride setting yet since there are still around 200 errors that require further attention
For #120675 - Manually fix a few cases the automation missed - Fix cases where an injected service is incorrectly being re-declared in a subclass
For #120675 - Manually fix a few more cases automation missed - Fix cases where an injected service is incorrectly being re-declared in a subclass
Current statusI've automatically added I also made two passes at the remaining errors. There were two types of issues I addressed here:
Next stepsThe remaining 100 errors need to be reviewed manually so I'm going to assign area owners. Please re-assign if needed To test building with update: About 15 errors remaining:
|
* Pick up new TS 4.3 Also tests adding override keywords for extensions as part of microsoft#120675 * Update to daily TS and workaround TS 4.3 issue Works around microsoft/TypeScript#43578
For microsoft#120675 This uses a script to add the override keyword to places that need it in the codebase Note that we can't enable the --noImplicitOverride setting yet since there are still around 200 errors that require further attention
For microsoft#120675 - Manually fix a few cases the automation missed - Fix cases where an injected service is incorrectly being re-declared in a subclass
For microsoft#120675 - Manually fix a few more cases automation missed - Fix cases where an injected service is incorrectly being re-declared in a subclass
We aren't tackling those given TS has acknowledged the issue and has a fix ready, right? |
Agreed. |
Hi folks! Seems the fix has already merged. |
@alexdima @sbatten Just 6 errors remaining! Please take a look when you have a chance @jrieken @alexdima Do you have any idea about why
In our source, get version(): number {
return this._versionId;
} However in the |
Yes, TypeScript is sometimes incorrect when invoking Find all references and this was one of those cases, where finding all references on To resolve the problem, I added another interface and an explicit |
Done with 66fd0cb Thanks everyone! |
--noImplicitOverride
TS 4.3 adds a new strictness option:
--noImplicitOverride
. This requires that you use theoverride
keyword when overriding and method:To fix this, simply add the
override
keyword: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)The text was updated successfully, but these errors were encountered: