-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Allow override
as parameter property
#43831
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
andrewbranch
merged 6 commits into
microsoft:master
from
andrewbranch:feature/override-parameter-property
Apr 28, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b435e1c
Allow `override` as parameter property
andrewbranch 97ee23a
Update other baseline
andrewbranch 38700c9
Add test for override on normal parameter
andrewbranch 0b4e464
Copy typo fix
andrewbranch c5ee125
Update baselines
andrewbranch e058849
Update API baseline
andrewbranch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests/baselines/reference/overrideParameterProperty.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
tests/cases/conformance/override/overrideParameterProperty.ts(20,24): error TS1029: 'public' modifier must precede 'override' modifier. | ||
tests/cases/conformance/override/overrideParameterProperty.ts(25,5): error TS2369: A parameter property is only allowed in a constructor implementation. | ||
|
||
|
||
==== tests/cases/conformance/override/overrideParameterProperty.ts (2 errors) ==== | ||
class Base { | ||
p1!: string; | ||
} | ||
|
||
class C1 extends Base { | ||
constructor(public override p1: "hello") { | ||
super(); | ||
this.p1; | ||
} | ||
} | ||
|
||
class C2 extends Base { | ||
constructor(override p1: "hello") { | ||
super(); | ||
this.p1; | ||
} | ||
} | ||
|
||
class C3 extends Base { | ||
constructor(override public p1: "hello") { | ||
~~~~~~ | ||
!!! error TS1029: 'public' modifier must precede 'override' modifier. | ||
super(); | ||
this.p1; | ||
} | ||
|
||
m(override p1: "hello") {} | ||
~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2369: A parameter property is only allowed in a constructor implementation. | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//// [overrideParameterProperty.ts] | ||
class Base { | ||
p1!: string; | ||
} | ||
|
||
class C1 extends Base { | ||
constructor(public override p1: "hello") { | ||
super(); | ||
this.p1; | ||
} | ||
} | ||
|
||
class C2 extends Base { | ||
constructor(override p1: "hello") { | ||
super(); | ||
this.p1; | ||
} | ||
} | ||
|
||
class C3 extends Base { | ||
constructor(override public p1: "hello") { | ||
super(); | ||
this.p1; | ||
} | ||
|
||
m(override p1: "hello") {} | ||
} | ||
|
||
|
||
//// [overrideParameterProperty.js] | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var Base = /** @class */ (function () { | ||
function Base() { | ||
} | ||
return Base; | ||
}()); | ||
var C1 = /** @class */ (function (_super) { | ||
__extends(C1, _super); | ||
function C1(p1) { | ||
var _this = _super.call(this) || this; | ||
_this.p1 = p1; | ||
_this.p1; | ||
return _this; | ||
} | ||
return C1; | ||
}(Base)); | ||
var C2 = /** @class */ (function (_super) { | ||
__extends(C2, _super); | ||
function C2(p1) { | ||
var _this = _super.call(this) || this; | ||
_this.p1 = p1; | ||
_this.p1; | ||
return _this; | ||
} | ||
return C2; | ||
}(Base)); | ||
var C3 = /** @class */ (function (_super) { | ||
__extends(C3, _super); | ||
function C3(p1) { | ||
var _this = _super.call(this) || this; | ||
_this.p1 = p1; | ||
_this.p1; | ||
return _this; | ||
} | ||
C3.prototype.m = function (p1) { }; | ||
return C3; | ||
}(Base)); |
63 changes: 63 additions & 0 deletions
63
tests/baselines/reference/overrideParameterProperty.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
=== tests/cases/conformance/override/overrideParameterProperty.ts === | ||
class Base { | ||
>Base : Symbol(Base, Decl(overrideParameterProperty.ts, 0, 0)) | ||
|
||
p1!: string; | ||
>p1 : Symbol(Base.p1, Decl(overrideParameterProperty.ts, 0, 12)) | ||
} | ||
|
||
class C1 extends Base { | ||
>C1 : Symbol(C1, Decl(overrideParameterProperty.ts, 2, 1)) | ||
>Base : Symbol(Base, Decl(overrideParameterProperty.ts, 0, 0)) | ||
|
||
constructor(public override p1: "hello") { | ||
>p1 : Symbol(C1.p1, Decl(overrideParameterProperty.ts, 5, 14)) | ||
|
||
super(); | ||
>super : Symbol(Base, Decl(overrideParameterProperty.ts, 0, 0)) | ||
|
||
this.p1; | ||
>this.p1 : Symbol(C1.p1, Decl(overrideParameterProperty.ts, 5, 14)) | ||
>this : Symbol(C1, Decl(overrideParameterProperty.ts, 2, 1)) | ||
>p1 : Symbol(C1.p1, Decl(overrideParameterProperty.ts, 5, 14)) | ||
} | ||
} | ||
|
||
class C2 extends Base { | ||
>C2 : Symbol(C2, Decl(overrideParameterProperty.ts, 9, 1)) | ||
>Base : Symbol(Base, Decl(overrideParameterProperty.ts, 0, 0)) | ||
|
||
constructor(override p1: "hello") { | ||
>p1 : Symbol(C2.p1, Decl(overrideParameterProperty.ts, 12, 14)) | ||
|
||
super(); | ||
>super : Symbol(Base, Decl(overrideParameterProperty.ts, 0, 0)) | ||
|
||
this.p1; | ||
>this.p1 : Symbol(C2.p1, Decl(overrideParameterProperty.ts, 12, 14)) | ||
>this : Symbol(C2, Decl(overrideParameterProperty.ts, 9, 1)) | ||
>p1 : Symbol(C2.p1, Decl(overrideParameterProperty.ts, 12, 14)) | ||
} | ||
} | ||
|
||
class C3 extends Base { | ||
>C3 : Symbol(C3, Decl(overrideParameterProperty.ts, 16, 1)) | ||
>Base : Symbol(Base, Decl(overrideParameterProperty.ts, 0, 0)) | ||
|
||
constructor(override public p1: "hello") { | ||
>p1 : Symbol(C3.p1, Decl(overrideParameterProperty.ts, 19, 14)) | ||
|
||
super(); | ||
>super : Symbol(Base, Decl(overrideParameterProperty.ts, 0, 0)) | ||
|
||
this.p1; | ||
>this.p1 : Symbol(C3.p1, Decl(overrideParameterProperty.ts, 19, 14)) | ||
>this : Symbol(C3, Decl(overrideParameterProperty.ts, 16, 1)) | ||
>p1 : Symbol(C3.p1, Decl(overrideParameterProperty.ts, 19, 14)) | ||
} | ||
|
||
m(override p1: "hello") {} | ||
>m : Symbol(C3.m, Decl(overrideParameterProperty.ts, 22, 3)) | ||
>p1 : Symbol(p1, Decl(overrideParameterProperty.ts, 24, 4)) | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
=== tests/cases/conformance/override/overrideParameterProperty.ts === | ||
class Base { | ||
>Base : Base | ||
|
||
p1!: string; | ||
>p1 : string | ||
} | ||
|
||
class C1 extends Base { | ||
>C1 : C1 | ||
>Base : Base | ||
|
||
constructor(public override p1: "hello") { | ||
>p1 : "hello" | ||
|
||
super(); | ||
>super() : void | ||
>super : typeof Base | ||
|
||
this.p1; | ||
>this.p1 : "hello" | ||
>this : this | ||
>p1 : "hello" | ||
} | ||
} | ||
|
||
class C2 extends Base { | ||
>C2 : C2 | ||
>Base : Base | ||
|
||
constructor(override p1: "hello") { | ||
>p1 : "hello" | ||
|
||
super(); | ||
>super() : void | ||
>super : typeof Base | ||
|
||
this.p1; | ||
>this.p1 : "hello" | ||
>this : this | ||
>p1 : "hello" | ||
} | ||
} | ||
|
||
class C3 extends Base { | ||
>C3 : C3 | ||
>Base : Base | ||
|
||
constructor(override public p1: "hello") { | ||
>p1 : "hello" | ||
|
||
super(); | ||
>super() : void | ||
>super : typeof Base | ||
|
||
this.p1; | ||
>this.p1 : "hello" | ||
>this : this | ||
>p1 : "hello" | ||
} | ||
|
||
m(override p1: "hello") {} | ||
>m : (p1: "hello") => void | ||
>p1 : "hello" | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
tests/cases/conformance/override/overrideParameterProperty.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// @noImplicitOverride: true | ||
|
||
class Base { | ||
p1!: string; | ||
} | ||
|
||
class C1 extends Base { | ||
constructor(public override p1: "hello") { | ||
super(); | ||
this.p1; | ||
} | ||
} | ||
|
||
class C2 extends Base { | ||
constructor(override p1: "hello") { | ||
super(); | ||
this.p1; | ||
} | ||
} | ||
|
||
class C3 extends Base { | ||
constructor(override public p1: "hello") { | ||
super(); | ||
this.p1; | ||
} | ||
|
||
m(override p1: "hello") {} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.