-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Add override keyword #13217
Add override keyword #13217
Changes from 4 commits
65f98b7
fb705a6
3143818
a1cdd8c
a186758
3626403
c791e7c
7dbf75d
5fe3b4d
489d09c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ namespace ts.JsDoc { | |
"private", | ||
"property", | ||
"public", | ||
"override", | ||
"requires", | ||
"returns", | ||
"see", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
tests/cases/compiler/noImplicitOverride.ts(11,5): error TS90034: Class member 'toString' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.Object) | ||
tests/cases/compiler/noImplicitOverride.ts(12,5): error TS90034: Class member 'hasOwnProperty' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.Object) | ||
tests/cases/compiler/noImplicitOverride.ts(18,5): error TS90034: Class member 'toString' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.toString) | ||
tests/cases/compiler/noImplicitOverride.ts(19,5): error TS90034: Class member 'hasOwnProperty' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.hasOwnProperty) | ||
tests/cases/compiler/noImplicitOverride.ts(25,5): error TS2322: Type '(prop: string) => number' is not assignable to type '(v: string) => boolean'. | ||
Class member 'hasOwnProperty' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.hasOwnProperty) | ||
tests/cases/compiler/noImplicitOverride.ts(31,12): error TS90034: Class member 'userId' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.Base) | ||
tests/cases/compiler/noImplicitOverride.ts(35,9): error TS90034: Class member 'name' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.Base) | ||
tests/cases/compiler/noImplicitOverride.ts(43,5): error TS1070: 'override' modifier cannot appear on a type member. | ||
tests/cases/compiler/noImplicitOverride.ts(52,29): error TS90034: Class member 'userId' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.Base) | ||
|
||
|
||
==== tests/cases/compiler/noImplicitOverride.ts (9 errors) ==== | ||
|
||
class Base { | ||
get name(): string { | ||
return 'Base'; | ||
} | ||
getMeaningOfLife(): number { return 42; } | ||
public userId: number = 1; | ||
} | ||
|
||
class RejectWhenOverrideMissingOnInheritedMethod extends Object { | ||
toString(): string { return 'foo'; }; | ||
~~~~~~~~ | ||
!!! error TS90034: Class member 'toString' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.Object) | ||
hasOwnProperty(prop: string): boolean { | ||
~~~~~~~~~~~~~~ | ||
!!! error TS90034: Class member 'hasOwnProperty' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.Object) | ||
return super.hasOwnProperty(prop); | ||
} | ||
} | ||
|
||
class RejectWhenOverrideMissingOnAugmentedProperty { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include a positive version of this test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
toString(): string { return 'foo'; }; | ||
~~~~~~~~ | ||
!!! error TS90034: Class member 'toString' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.toString) | ||
hasOwnProperty(prop: string): boolean { | ||
~~~~~~~~~~~~~~ | ||
!!! error TS90034: Class member 'hasOwnProperty' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.hasOwnProperty) | ||
return false; | ||
} | ||
} | ||
|
||
class RejectWhenOverrideTypeMismatchOnMethodThatMasksObjectTypeMember { | ||
hasOwnProperty(prop: string): number { | ||
~~~~~~~~~~~~~~ | ||
!!! error TS2322: Type '(prop: string) => number' is not assignable to type '(v: string) => boolean'. | ||
!!! error TS2322: Class member 'hasOwnProperty' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.hasOwnProperty) | ||
return -1; | ||
} | ||
} | ||
|
||
class RejectWhenOverrideMissingOnInheritedProperty extends Base { | ||
public userId = 2; | ||
~~~~~~ | ||
!!! error TS90034: Class member 'userId' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.Base) | ||
} | ||
|
||
class RejectWhenOverrideMissingOnInheritedAccessor extends Base { | ||
get name(): string { return 'foo'; }; | ||
~~~~ | ||
!!! error TS90034: Class member 'name' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.Base) | ||
} | ||
|
||
interface Shape { | ||
getWidth(): number; | ||
} | ||
|
||
interface RejectWhenOverrideOnAbstractDeclaration_Line extends Shape { | ||
override getWidth(): number; | ||
~~~~~~~~ | ||
!!! error TS1070: 'override' modifier cannot appear on a type member. | ||
} | ||
|
||
interface AcceptWhenOverrideNotOnAbstractDeclaration_Line extends Shape { | ||
// abstract members don't need to be declared override | ||
getWidth(): number; | ||
} | ||
|
||
class FIXME_AcceptWhenOverrideSpecifiedByJSDocAnnotation extends Base { | ||
/** @override */ public userId: number = 2; | ||
~~~~~~ | ||
!!! error TS90034: Class member 'userId' must be marked 'override' when noImplicitOverride is enabled (augmented from Object.Base) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something's wrong with the way this is being rendered. We shouldn't have
Object.
in front of all of these. (Except e.g.Object.toString
which is actually a property of Object.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed