-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(48653): throw an error on an invalid optional chain from new expr…
…ession (#48656)
- Loading branch information
1 parent
c6447f9
commit 2cb8ee2
Showing
7 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/invalidOptionalChainFromNewExpression.errors.txt
This file contains 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,13 @@ | ||
tests/cases/compiler/invalidOptionalChainFromNewExpression.ts(5,6): error TS1209: Invalid optional chain from new expression. Did you mean to call 'A()'? | ||
|
||
|
||
==== tests/cases/compiler/invalidOptionalChainFromNewExpression.ts (1 errors) ==== | ||
class A { | ||
b() {} | ||
} | ||
|
||
new A?.b() // error | ||
~~ | ||
!!! error TS1209: Invalid optional chain from new expression. Did you mean to call 'A()'? | ||
new A()?.b() // ok | ||
|
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/invalidOptionalChainFromNewExpression.js
This file contains 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,19 @@ | ||
//// [invalidOptionalChainFromNewExpression.ts] | ||
class A { | ||
b() {} | ||
} | ||
|
||
new A?.b() // error | ||
new A()?.b() // ok | ||
|
||
|
||
//// [invalidOptionalChainFromNewExpression.js] | ||
var _a, _b; | ||
var A = /** @class */ (function () { | ||
function A() { | ||
} | ||
A.prototype.b = function () { }; | ||
return A; | ||
}()); | ||
(_a = new A) === null || _a === void 0 ? void 0 : _a.b(); // error | ||
(_b = new A()) === null || _b === void 0 ? void 0 : _b.b(); // ok |
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/invalidOptionalChainFromNewExpression.symbols
This file contains 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,18 @@ | ||
=== tests/cases/compiler/invalidOptionalChainFromNewExpression.ts === | ||
class A { | ||
>A : Symbol(A, Decl(invalidOptionalChainFromNewExpression.ts, 0, 0)) | ||
|
||
b() {} | ||
>b : Symbol(A.b, Decl(invalidOptionalChainFromNewExpression.ts, 0, 9)) | ||
} | ||
|
||
new A?.b() // error | ||
>new A?.b : Symbol(A.b, Decl(invalidOptionalChainFromNewExpression.ts, 0, 9)) | ||
>A : Symbol(A, Decl(invalidOptionalChainFromNewExpression.ts, 0, 0)) | ||
>b : Symbol(A.b, Decl(invalidOptionalChainFromNewExpression.ts, 0, 9)) | ||
|
||
new A()?.b() // ok | ||
>new A()?.b : Symbol(A.b, Decl(invalidOptionalChainFromNewExpression.ts, 0, 9)) | ||
>A : Symbol(A, Decl(invalidOptionalChainFromNewExpression.ts, 0, 0)) | ||
>b : Symbol(A.b, Decl(invalidOptionalChainFromNewExpression.ts, 0, 9)) | ||
|
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/invalidOptionalChainFromNewExpression.types
This file contains 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,22 @@ | ||
=== tests/cases/compiler/invalidOptionalChainFromNewExpression.ts === | ||
class A { | ||
>A : A | ||
|
||
b() {} | ||
>b : () => void | ||
} | ||
|
||
new A?.b() // error | ||
>new A?.b() : void | ||
>new A?.b : () => void | ||
>new A : A | ||
>A : typeof A | ||
>b : () => void | ||
|
||
new A()?.b() // ok | ||
>new A()?.b() : void | ||
>new A()?.b : () => void | ||
>new A() : A | ||
>A : typeof A | ||
>b : () => void | ||
|
6 changes: 6 additions & 0 deletions
6
tests/cases/compiler/invalidOptionalChainFromNewExpression.ts
This file contains 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,6 @@ | ||
class A { | ||
b() {} | ||
} | ||
|
||
new A?.b() // error | ||
new A()?.b() // ok |