Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39755,6 +39755,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
case SyntaxKind.AwaitExpression:
case SyntaxKind.CallExpression:
case SyntaxKind.ElementAccessExpression:
case SyntaxKind.MetaProperty:
case SyntaxKind.NewExpression:
case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.YieldExpression:
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/predicateSemantics.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,11 @@ predicateSemantics.ts(52,14): error TS2869: Right operand of ?? is unreachable b
~~~~~~~~~~
!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
}

// https://github.com/microsoft/TypeScript/issues/60439
class X {
constructor() {
const p = new.target ?? 32;
}
}

16 changes: 16 additions & 0 deletions tests/baselines/reference/predicateSemantics.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ function foo(this: Object | undefined) {
const e = (i++, i++) ?? true; // error
const f = (maybe, i++) ?? true; // error
}

// https://github.com/microsoft/TypeScript/issues/60439
class X {
constructor() {
const p = new.target ?? 32;
}
}


//// [predicateSemantics.js]
Expand Down Expand Up @@ -106,3 +113,12 @@ function foo() {
var e = (_h = (i++, i++)) !== null && _h !== void 0 ? _h : true; // error
var f = (_j = (maybe, i++)) !== null && _j !== void 0 ? _j : true; // error
}
// https://github.com/microsoft/TypeScript/issues/60439
var X = /** @class */ (function () {
function X() {
var _newTarget = this.constructor;
var _a;
var p = (_a = _newTarget) !== null && _a !== void 0 ? _a : 32;
}
return X;
}());
12 changes: 12 additions & 0 deletions tests/baselines/reference/predicateSemantics.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,15 @@ function foo(this: Object | undefined) {
>i : Symbol(i, Decl(predicateSemantics.ts, 48, 5))
}

// https://github.com/microsoft/TypeScript/issues/60439
class X {
>X : Symbol(X, Decl(predicateSemantics.ts, 52, 1))

constructor() {
const p = new.target ?? 32;
>p : Symbol(p, Decl(predicateSemantics.ts, 57, 9))
>new.target : Symbol(X, Decl(predicateSemantics.ts, 52, 1))
>target : Symbol(X, Decl(predicateSemantics.ts, 52, 1))
}
}

20 changes: 20 additions & 0 deletions tests/baselines/reference/predicateSemantics.types
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,23 @@ function foo(this: Object | undefined) {
> : ^^^^
}

// https://github.com/microsoft/TypeScript/issues/60439
class X {
>X : X
> : ^

constructor() {
const p = new.target ?? 32;
>p : 32 | typeof X
> : ^^^^^^^^^^^^^
>new.target ?? 32 : 32 | typeof X
> : ^^^^^^^^^^^^^
>new.target : typeof X
> : ^^^^^^^^
>target : typeof X
> : ^^^^^^^^
>32 : 32
> : ^^
}
}

7 changes: 7 additions & 0 deletions tests/cases/compiler/predicateSemantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ function foo(this: Object | undefined) {
const e = (i++, i++) ?? true; // error
const f = (maybe, i++) ?? true; // error
}

// https://github.com/microsoft/TypeScript/issues/60439
class X {
constructor() {
const p = new.target ?? 32;
}
}