diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e9241cb0b7457..05b0847dd4de7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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; diff --git a/tests/baselines/reference/satisfiesEmit.errors.txt b/tests/baselines/reference/satisfiesEmit.errors.txt new file mode 100644 index 0000000000000..45f8097024cf3 --- /dev/null +++ b/tests/baselines/reference/satisfiesEmit.errors.txt @@ -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'. + \ No newline at end of file diff --git a/tests/baselines/reference/satisfiesEmit.js b/tests/baselines/reference/satisfiesEmit.js new file mode 100644 index 0000000000000..6851dbe9f8dd5 --- /dev/null +++ b/tests/baselines/reference/satisfiesEmit.js @@ -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; diff --git a/tests/baselines/reference/satisfiesEmit.symbols b/tests/baselines/reference/satisfiesEmit.symbols new file mode 100644 index 0000000000000..051902990e69b --- /dev/null +++ b/tests/baselines/reference/satisfiesEmit.symbols @@ -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) + diff --git a/tests/baselines/reference/satisfiesEmit.types b/tests/baselines/reference/satisfiesEmit.types new file mode 100644 index 0000000000000..9546af9e238c6 --- /dev/null +++ b/tests/baselines/reference/satisfiesEmit.types @@ -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 + diff --git a/tests/cases/compiler/satisfiesEmit.ts b/tests/cases/compiler/satisfiesEmit.ts new file mode 100644 index 0000000000000..bf2c6156e95ee --- /dev/null +++ b/tests/cases/compiler/satisfiesEmit.ts @@ -0,0 +1,3 @@ +// This import should not be elided in the emitted JS +import a = require("foo"); +const p = a satisfies bleh;