Skip to content

Commit eb5419f

Browse files
authoredDec 5, 2022
Cherry-pick #51704 to release 4.9 (#51712)
* Manual port of #51704 * Add a testcase
1 parent b4d382b commit eb5419f

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed
 

‎src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32707,13 +32707,13 @@ namespace ts {
3270732707

3270832708
function checkSatisfiesExpression(node: SatisfiesExpression) {
3270932709
checkSourceElement(node.type);
32710+
const exprType = checkExpression(node.expression);
3271032711

3271132712
const targetType = getTypeFromTypeNode(node.type);
3271232713
if (isErrorType(targetType)) {
3271332714
return targetType;
3271432715
}
3271532716

32716-
const exprType = checkExpression(node.expression);
3271732717
checkTypeAssignableToAndOptionallyElaborate(exprType, targetType, node.type, node.expression, Diagnostics.Type_0_does_not_satisfy_the_expected_type_1);
3271832718

3271932719
return exprType;
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+
+12
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;
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+
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

+3
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)
Please sign in to comment.