Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unconditionally call checkExpression from checkSatisfiesExpression #51704

Merged
merged 2 commits into from Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Expand Up @@ -33704,13 +33704,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;
Expand Down
13 changes: 13 additions & 0 deletions 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'.

12 changes: 12 additions & 0 deletions 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;
10 changes: 10 additions & 0 deletions 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)

10 changes: 10 additions & 0 deletions 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

3 changes: 3 additions & 0 deletions 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;