8000 --noImplicitOverride by Kingwl · Pull Request #39669 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

--noImplicitOverride #39669

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

Merged
merged 76 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
8b90b8d
wip: add types
Kingwl Jul 15, 2020
ea5608a
wip
Kingwl Jul 17, 2020
9371d87
Add cases
Kingwl Jul 17, 2020
6cb7f5e
Add some case
Kingwl Jul 17, 2020
061cd27
Add more check
Kingwl Jul 20, 2020
37ada55
accept baseline
Kingwl Jul 20, 2020
6401e1a
add abstract abd declare method
Kingwl Jul 20, 2020
be00363
add override in declaration
Kingwl Jul 20, 2020
fbb6e28
accept baseline
Kingwl Jul 20, 2020
6014a3a
add property override
Kingwl Jul 21, 2020
a65df91
Fix decalre modifier
Kingwl Jul 21, 2020
43d9f70
update baseline
Kingwl Jul 21, 2020
e73c941
Add more cases
Kingwl Jul 21, 2020
c0edf6f
make lint happy
Kingwl Jul 21, 2020
dca93ac
make lint happy
Kingwl Jul 21, 2020
2fd560a
Update description
Kingwl Jul 21, 2020
94187c7
Add codefix
Kingwl Aug 19, 2020
2b57fbd
simplify code
Kingwl Aug 19, 2020
3a2286b
Merge branch 'master' into exprement-override
Kingwl Aug 19, 2020
d34afb9
accept baseline
Kingwl Aug 19, 2020
b4614d1
Update desc
Kingwl Aug 21, 2020
1ef034d
Accept baseline
Kingwl Aug 21, 2020
aebfb28
Add override completions
Kingwl Aug 24, 2020
7753983
filter out implements field in override context
Kingwl Aug 24, 2020
5c04ccc
fix tests
Kingwl Aug 24, 2020
add16c9
Add parameter property check
Kingwl Aug 24, 2020
5316e2f
Accept baseline
Kingwl Aug 24, 2020
f36fede
acept baseline
Kingwl Aug 24, 2020
811bd1e
Add parameter property to declaration code action
Kingwl Aug 25, 2020
d0f5095
Add quickfix for override parameter property
Kingwl Aug 25, 2020
dd51815
Merge branch 'master' into exprement-override
Kingwl Sep 1, 2020
22bb09d
fix code style
Kingwl Sep 3, 2020
eee3b77
Add override with interface tests
Kingwl Sep 3, 2020
f94e93c
Add more cases about modifier position
Kingwl Sep 3, 2020
74f14c3
Merge branch 'master' into exprement-override
Kingwl Sep 14, 2020
e35ee17
rename flag
Kingwl Sep 14, 2020
d8fda5f
rename flags
Kingwl Sep 14, 2020
18434fd
Added tests.
DanielRosenwasser Sep 14, 2020
5ab5a7f
Accepted baselines.
DanielRosenwasser Sep 15, 2020
f52822a
Always issue errors for unnecessary 'override' modifiers.
DanielRosenwasser Sep 15, 2020
48c23a5
Accepted baselines.
DanielRosenwasser Sep 15, 2020
a3f0443
Merge branch 'master' into exprement-override
Kingwl Sep 15, 2020
cdd0739
Override perf (#4)
Kingwl Sep 15, 2020
8e53ad3
Merge branch 'master' into exprement-override
Kingwl Sep 16, 2020
827bc95
Do not issue error if implement abstract
Kingwl Sep 16, 2020
618f883
Add abstract-spec check
Kingwl Sep 16, 2020
bc4d758
Avoid override dead lock
Kingwl Sep 16, 2020
47296d6
Add more case
Kingwl Sep 16, 2020
5d19a90
Add codefix for new error
Kingwl Sep 16, 2020
68e1440
Fix error message
Kingwl Sep 16, 2020
82109e9
Merge branch 'master' into exprement-override
Kingwl Oct 30, 2020
2552495
Add jsdoc override tag (#6)
Kingwl Nov 2, 2020
cf5dc7e
Override jsdoc tag (#7)
Kingwl Nov 2, 2020
b65d244
Disallow codefix in js
Kingwl Nov 2, 2020
84cc69d
Merge branch 'master' into exprement-override
Kingwl Nov 5, 2020
6d89a7a
update baseline
Kingwl Nov 5, 2020
062f149
update baseline
Kingwl Nov 5, 2020
feb9093
Omit override in d.ts
Kingwl Nov 5, 2020
0c09a2e
Add more case in js
Kingwl Nov 5, 2020
3cf3c28
Accept baseline
Kingwl Nov 5, 2020
d874ae8
fix override js test
Kingwl Nov 6, 2020
e361ddc
Merge branch 'master' into exprement-override
Kingwl Dec 31, 2020
40da344
Merge branch 'master' into exprement-override
Kingwl Jan 7, 2021
f9384bc
fix crlf
Kingwl Jan 7, 2021
eea8259
Revert merge conflict changes
Kingwl Jan 7, 2021
ff3cbc1
Accept baseline
Kingwl Jan 7, 2021
a3766d2
Avoid space
Kingwl Jan 7, 2021
e2c245e
Merge branch 'master' into exprement-override
Kingwl Feb 4, 2021
8f3dcb9
Merge branch 'master' into exprement-override
Kingwl Mar 5, 2021
1db64fb
Fix CR issues
Kingwl Mar 5, 2021
71c00d5
Merge branch 'master' into exprement-override
Kingwl Mar 8, 2021
e3c0993
Accept baseline
Kingwl Mar 8, 2021
89517a0
Fix typo and add more check
Kingwl Mar 9, 2021
6c8d00d
Fix error name
Kingwl Mar 9, 2021
bbfb7eb
Merge branch 'master' into exprement-override
Kingwl Mar 10, 2021
4575b5a
Merge branch 'master' into exprement-override
Kingwl Mar 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more check
  • Loading branch information
Kingwl committed Jul 20, 2020
commit 061cd27da6dadcaaed23ffaab38bae20a343808c
43 changes: 22 additions & 21 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34375,7 +34375,9 @@ namespace ts {
}
}

issueMemberWithOverride(node, type, typeWithThis);
if (compilerOptions.pedanticOverride) {
issueMemberWithOverride(node, type, typeWithThis);
}

const implementedTypeNodes = getEffectiveImplementsTypeNodes(node);
if (implementedTypeNodes) {
Expand Down Expand Up @@ -34411,32 +34413,31 @@ namespace ts {
}
}

function issueMemberWithOverride (node: ClassLikeDeclaration, type: InterfaceType, typeWithThis: Type) {
function issueMemberWithOverride(node: ClassLikeDeclaration, type: InterfaceType, typeWithThis: Type) {
const baseTypeNode = getEffectiveBaseTypeNode(node);
const baseTypes = baseTypeNode && getBaseTypes(type);
const baseWithThis = baseTypes?.length ? getTypeWithThisArgument(first(baseTypes), type.thisType) : undefined;

for (const member of node.members) {
const hasOverride = hasOverrideModifier(member);
if (hasOverride && !baseTypeNode) {
error(member, Diagnostics._0_is_deprecated, 'has override but not extended')
}
else if (baseTypeNode) {
const baseTypes = getBaseTypes(type);
if (baseTypes.length) {
const baseType = first(baseTypes);
const baseWithThis = getTypeWithThisArgument(baseType, type.thisType);

const declaredProp = member.name && getSymbolAtLocation(member.name) || getSymbolAtLocation(member);
if (declaredProp) {
const prop = getPropertyOfType(typeWithThis, declaredProp.escapedName);
const baseProp = getPropertyOfType(baseWithThis, declaredProp.escapedName);
if (prop && !baseProp && hasOverride) {
error(member, Diagnostics._0_is_deprecated, 'not founded in base class')
}
else if (prop && baseProp && !hasOverride) {
error(member, Diagnostics._0_is_deprecated, 'need override')
}
if (baseWithThis) {
const declaredProp = member.name && getSymbolAtLocation(member.name) || getSymbolAtLocation(member);
if (declaredProp) {
const baseClassName = typeToString(baseWithThis);
const prop = getPropertyOfType(typeWithThis, declaredProp.escapedName);
const baseProp = getPropertyOfType(baseWithThis, declaredProp.escapedName);
if (prop && !baseProp && hasOverride) {
error(member, Diagnostics.Method_cannot_have_override_modifier_because_it_s_not_existed_in_the_base_class_0, baseClassName);
}
else if (prop && baseProp && !hasOverride) {
error(member, Diagnostics.Method_must_have_override_modifier_because_it_s_override_the_base_class_0, baseClassName);
}
}
}
else if (hasOverride) {
const className = typeToString(type);
error(member, Diagnostics.Method_cannot_have_override_modifier_because_class_0_does_not_extended_another_class, className);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,14 @@ namespace ts {
category: Diagnostics.Additional_Checks,
description: Diagnostics.Report_errors_for_fallthrough_cases_in_switch_statement
},
{
name: "pedanticOverride",
type: "boolean",
affectsSemanticDiagnostics: true,
showInSimplifiedHelpView: false,
category: Diagnostics.Additional_Checks,
description: Diagnostics.Required_override_modifier_in_class_element
},

// Module Resolution
{
Expand Down
16 changes: 16 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3361,6 +3361,18 @@
"category": "Error",
"code": 4110
},
"Method cannot have override modifier because class '{0}' does not extended another class.": {
"category": "Error",
"code": 4111
},
"Method cannot have override modifier because it's not existed in the base class '{0}'.": {
"category": "Error",
"code": 4112
},
"Method must have override modifier because it's override the base class '{0}'.": {
"category": "Error",
"code": 4113
},

"The current host does not support the '{0}' option.": {
"category": "Error",
Expand Down Expand Up @@ -4653,6 +4665,10 @@
"category": "Error",
"code": 6504
},
"Required override modifier in class element": {
"category": "Error",
"code": 6801
},

"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5719,6 +5719,7 @@ namespace ts {
paths?: MapLike<string[]>;
/*@internal*/ plugins?: PluginImport[];
preserveConstEnums?: boolean;
pedanticOverride?: boolean;
preserveSymlinks?: boolean;
/* @internal */ preserveWatchOutput?: boolean;
project?: string;
Expand Down
77 changes: 54 additions & 23 deletions tests/baselines/reference/override1.errors.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,71 @@
tests/cases/conformance/override/override1.ts(15,5): suggestion TS6385: 'need override' is deprecated
tests/cases/conformance/override/override1.ts(19,14): suggestion TS6385: 'not founded in base class' is deprecated
tests/cases/conformance/override/override1.ts(25,14): suggestion TS6385: 'has override but not extended' is deprecated
tests/cases/conformance/override/override1.ts(9,5): error TS4113: Method must have override modifier because it's override the base class 'B'.
tests/cases/conformance/override/override1.ts(11,14): error TS4112: Method cannot have override modifier because it's not existed in the base class 'B'.
tests/cases/conformance/override/override1.ts(15,14): error TS4111: Method cannot have override modifier because class 'C' does not extended another class.
tests/cases/conformance/override/override1.ts(22,9): error TS4113: Method must have override modifier because it's override the base class 'B'.
tests/cases/conformance/override/override1.ts(24,18): error TS4112: Method cannot have override modifier because it's not existed in the base class 'B'.
tests/cases/conformance/override/override1.ts(33,5): error TS4113: Method must have override modifier because it's override the base class '(Anonymous class)'.
tests/cases/conformance/override/override1.ts(37,14): error TS4112: Method cannot have override modifier because it's not existed in the base class '(Anonymous class)'.
tests/cases/conformance/override/override1.ts(42,18): error TS4111: Method cannot have override modifier because class '(Anonymous class)' does not extended another class.


==== tests/cases/conformance/override/override1.ts (3 errors) ====
==== tests/cases/conformance/override/override1.ts (8 errors) ====
class B {
foo (v: string) {

}
fooo (v: string) {

}
foo (v: string) {}
fooo (v: string) {}
}

class D extends B {
override foo (v: string) {
override foo (v: string) {}

}

fooo (v: string) {
fooo (v: string) {}
~~~~
!!! suggestion TS6385: 'need override' is deprecated

}
!!! error TS4113: Method must have override modifier because it's override the base class 'B'.

override bar(v: string) {
override bar(v: string) {}
~~~
!!! suggestion TS6385: 'not founded in base class' is deprecated

}
!!! error TS4112: Method cannot have override modifier because it's not existed in the base class 'B'.
}

class C {
override foo(v: string) {
override foo(v: string) {}
~~~
!!! suggestion TS6385: 'has override but not extended' is deprecated
!!! error TS4111: Method cannot have override modifier because class 'C' does not extended another class.
}

function f () {
return class extends B {
override foo (v: string) {}

fooo (v: string) {}
~~~~
!!! err 10000 or TS4113: Method must have override modifier because it's override the base class 'B'.

override bar(v: string) {}
~~~
!!! error TS4112: Method cannot have override modifier because it's not existed in the base class 'B'.
}
}

class E extends (class {
foo () { }
bar () { }
}) {
override foo () { }
bar () { }
~~~
!!! error TS4113: Method must have override modifier because it's override the base class '(Anonymous class)'.

baz() {}

override bazz () {}
~~~~
!!! error TS4112: Method cannot have override modifier because it's not existed in the base class '(Anonymous class)'.
}

function ff () {
return class {
override foo () {}
~~~
!!! error TS4111: Method cannot have override modifier because class '(Anonymous class)' does not extended another class.
}
}
101 changes: 74 additions & 27 deletions tests/baselines/reference/override1.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
//// [override1.ts]
class B {
foo (v: string) {

}
fooo (v: string) {

}
foo (v: string) {}
fooo (v: string) {}
}

class D extends B {
override foo (v: string) {
override foo (v: string) {}

}
fooo (v: string) {}

fooo (v: string) {

}
override bar(v: string) {}
}

override bar(v: string) {

class C {
override foo(v: string) {}
}

function f () {
return class extends B {
override foo (v: string) {}

fooo (v: string) {}

override bar(v: string) {}
}
}

class C {
override foo(v: string) {
class E extends (class {
foo () { }
bar () { }
}) {
override foo () { }
bar () { }

baz() {}

override bazz () {}
}

function ff () {
return class {
override foo () {}
}
}

Expand All @@ -45,29 +61,60 @@ var __extends = (this && this.__extends) || (function () {
var B = /** @class */ (function () {
function B() {
}
B.prototype.foo = function (v) {
};
B.prototype.fooo = function (v) {
};
B.prototype.foo = function (v) { };
B.prototype.fooo = function (v) { };
return B;
}());
var D = /** @class */ (function (_super) {
__extends(D, _super);
function D() {
return _super !== null && _super.apply(this, arguments) || this;
}
D.prototype.foo = function (v) {
};
D.prototype.fooo = function (v) {
};
D.prototype.bar = function (v) {
};
D.prototype.foo = function (v) { };
D.prototype.fooo = function (v) { };
D.prototype.bar = function (v) { };
return D;
}(B));
var C = /** @class */ (function () {
function C() {
}
C.prototype.foo = function (v) {
};
C.prototype.foo = function (v) { };
return C;
}());
function f() {
return /** @class */ (function (_super) {
__extends(class_1, _super);
function class_1() {
return _super !== null && _super.apply(this, arguments) || this;
}
class_1.prototype.foo = function (v) { };
class_1.prototype.fooo = function (v) { };
class_1.prototype.bar = function (v) { };
return class_1;
}(B));
}
var E = /** @class */ (function (_super) {
__extends(E, _super);
function E() {
return _super !== null && _super.apply(this, arguments) || this;
}
E.prototype.foo = function () { };
E.prototype.bar = function () { };
E.prototype.baz = function () { };
E.prototype.bazz = function () { };
return E;
}((/** @class */ (function () {
function class_2() {
}
class_2.prototype.foo = function () { };
class_2.prototype.bar = function () { };
return class_2;
}()))));
function ff() {
return /** @class */ (function () {
function class_3() {
}
class_3.prototype.foo = function () { };
return class_3;
}());
}
Loading
0