Skip to content

Commit 9089d53

Browse files
Unconditionally call checkExpression from checkSatisfiesExpression (#51704)
* Unconditionally call `checkExpression` in `checkSatisfiesExpression` * A testcase
1 parent 70d5cb2 commit 9089d53

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33707,13 +33707,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3370733707

3370833708
function checkSatisfiesExpression(node: SatisfiesExpression) {
3370933709
checkSourceElement(node.type);
33710+
const exprType = checkExpression(node.expression);
3371033711

3371133712
const targetType = getTypeFromTypeNode(node.type);
3371233713
if (isErrorType(targetType)) {
3371333714
return targetType;
3371433715
}
3371533716

33716-
const exprType = checkExpression(node.expression);
3371733717
checkTypeAssignableToAndOptionallyElaborate(exprType, targetType, node.type, node.expression, Diagnostics.Type_0_does_not_satisfy_the_expected_type_1);
3371833718

3371933719
return exprType;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/cases/compiler/satisfiesEmit.ts(2,20): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
2+
tests/cases/compiler/satisfiesEmit.ts(3,23): error TS2304: Cannot find name 'bleh'.
3+
4+
5+
==== tests/cases/compiler/satisfiesEmit.ts (2 errors) ====
6+
// This import should not be elided in the emitted JS
7+
import a = require("foo");
8+
~~~~~
9+
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
10+
const p = a satisfies bleh;
11+
~~~~
12+
!!! error TS2304: Cannot find name 'bleh'.
13+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [satisfiesEmit.ts]
2+
// This import should not be elided in the emitted JS
3+
import a = require("foo");
4+
const p = a satisfies bleh;
5+
6+
7+
//// [satisfiesEmit.js]
8+
"use strict";
9+
exports.__esModule = true;
10+
// This import should not be elided in the emitted JS
11+
var a = require("foo");
12+
var p = a;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/satisfiesEmit.ts ===
2+
// This import should not be elided in the emitted JS
3+
import a = require("foo");
4+
>a : Symbol(a, Decl(satisfiesEmit.ts, 0, 0))
5+
6+
const p = a satisfies bleh;
7+
>p : Symbol(p, Decl(satisfiesEmit.ts, 2, 5))
8+
>a : Symbol(a, Decl(satisfiesEmit.ts, 0, 0))
9+
>bleh : Symbol(bleh)
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/satisfiesEmit.ts ===
2+
// This import should not be elided in the emitted JS
3+
import a = require("foo");
4+
>a : any
5+
6+
const p = a satisfies bleh;
7+
>p : bleh
8+
>a satisfies bleh : bleh
9+
>a : any
10+

tests/cases/compiler/satisfiesEmit.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This import should not be elided in the emitted JS
2+
import a = require("foo");
3+
const p = a satisfies bleh;

0 commit comments

Comments
 (0)