Unconditionally call checkExpression from checkSatisfiesExpression (#51704)

* Unconditionally call `checkExpression` in `checkSatisfiesExpression`

* A testcase
This commit is contained in:
Ryan Cavanaugh 2022-12-01 09:11:37 -08:00 committed by GitHub
parent 70d5cb2827
commit 9089d5390a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 1 deletions

View File

@ -33707,13 +33707,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function checkSatisfiesExpression(node: SatisfiesExpression) {
checkSourceElement(node.type);
const exprType = checkExpression(node.expression);
const targetType = getTypeFromTypeNode(node.type);
if (isErrorType(targetType)) {
return targetType;
}
const exprType = checkExpression(node.expression);
checkTypeAssignableToAndOptionallyElaborate(exprType, targetType, node.type, node.expression, Diagnostics.Type_0_does_not_satisfy_the_expected_type_1);
return exprType;

View File

@ -0,0 +1,13 @@
tests/cases/compiler/satisfiesEmit.ts(2,20): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
tests/cases/compiler/satisfiesEmit.ts(3,23): error TS2304: Cannot find name 'bleh'.
==== tests/cases/compiler/satisfiesEmit.ts (2 errors) ====
// This import should not be elided in the emitted JS
import a = require("foo");
~~~~~
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
const p = a satisfies bleh;
~~~~
!!! error TS2304: Cannot find name 'bleh'.

View File

@ -0,0 +1,12 @@
//// [satisfiesEmit.ts]
// This import should not be elided in the emitted JS
import a = require("foo");
const p = a satisfies bleh;
//// [satisfiesEmit.js]
"use strict";
exports.__esModule = true;
// This import should not be elided in the emitted JS
var a = require("foo");
var p = a;

View File

@ -0,0 +1,10 @@
=== tests/cases/compiler/satisfiesEmit.ts ===
// This import should not be elided in the emitted JS
import a = require("foo");
>a : Symbol(a, Decl(satisfiesEmit.ts, 0, 0))
const p = a satisfies bleh;
>p : Symbol(p, Decl(satisfiesEmit.ts, 2, 5))
>a : Symbol(a, Decl(satisfiesEmit.ts, 0, 0))
>bleh : Symbol(bleh)

View File

@ -0,0 +1,10 @@
=== tests/cases/compiler/satisfiesEmit.ts ===
// This import should not be elided in the emitted JS
import a = require("foo");
>a : any
const p = a satisfies bleh;
>p : bleh
>a satisfies bleh : bleh
>a : any

View File

@ -0,0 +1,3 @@
// This import should not be elided in the emitted JS
import a = require("foo");
const p = a satisfies bleh;