diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e889a93ef2394..ce71bf227f2a5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -34571,7 +34571,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (isErrorType(targetType)) { return targetType; } - checkTypeAssignableToAndOptionallyElaborate(exprType, targetType, target, expression, Diagnostics.Type_0_does_not_satisfy_the_expected_type_1); + const errorNode = findAncestor(target.parent, n => n.kind === SyntaxKind.SatisfiesExpression || n.kind === SyntaxKind.JSDocSatisfiesTag); + checkTypeAssignableToAndOptionallyElaborate(exprType, targetType, errorNode, expression, Diagnostics.Type_0_does_not_satisfy_the_expected_type_1); return exprType; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6e4085a82ae27..951fad24d2c9a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -350,6 +350,7 @@ import { JSDocParameterTag, JSDocPropertyLikeTag, JSDocSatisfiesExpression, + JSDocSatisfiesTag, JSDocSignature, JSDocTag, JSDocTemplateTag, @@ -2231,6 +2232,14 @@ export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpa const pos = skipTrivia(sourceFile.text, (node as ReturnStatement | YieldExpression).pos); return getSpanOfTokenAtPosition(sourceFile, pos); } + case SyntaxKind.SatisfiesExpression: { + const pos = skipTrivia(sourceFile.text, (node as SatisfiesExpression).expression.end); + return getSpanOfTokenAtPosition(sourceFile, pos); + } + case SyntaxKind.JSDocSatisfiesTag: { + const pos = skipTrivia(sourceFile.text, (node as JSDocSatisfiesTag).tagName.pos); + return getSpanOfTokenAtPosition(sourceFile, pos); + } } if (errorNode === undefined) { diff --git a/tests/baselines/reference/checkJsdocSatisfiesTag1.errors.txt b/tests/baselines/reference/checkJsdocSatisfiesTag1.errors.txt index 9eca275c9bc14..78798d222df24 100644 --- a/tests/baselines/reference/checkJsdocSatisfiesTag1.errors.txt +++ b/tests/baselines/reference/checkJsdocSatisfiesTag1.errors.txt @@ -1,6 +1,6 @@ /a.js(21,44): error TS1360: Type '{ a: number; b: number; }' does not satisfy the expected type 'T1'. Object literal may only specify known properties, and 'b' does not exist in type 'T1'. -/a.js(22,28): error TS1360: Type '{}' does not satisfy the expected type 'T1'. +/a.js(22,17): error TS1360: Type '{}' does not satisfy the expected type 'T1'. Property 'a' is missing in type '{}' but required in type 'T1'. /a.js(31,49): error TS1360: Type '{ a: string; b: string; }' does not satisfy the expected type 'T4'. Object literal may only specify known properties, and 'b' does not exist in type 'T4'. @@ -32,7 +32,7 @@ !!! error TS1360: Type '{ a: number; b: number; }' does not satisfy the expected type 'T1'. !!! error TS1360: Object literal may only specify known properties, and 'b' does not exist in type 'T1'. const t3 = /** @satisfies {T1} */ ({}); - ~~ + ~~~~~~~~~ !!! error TS1360: Type '{}' does not satisfy the expected type 'T1'. !!! error TS1360: Property 'a' is missing in type '{}' but required in type 'T1'. !!! related TS2728 /a.js:3:4: 'a' is declared here. diff --git a/tests/baselines/reference/checkJsdocSatisfiesTag12.errors.txt b/tests/baselines/reference/checkJsdocSatisfiesTag12.errors.txt index 1775da83901e4..5d34c70e3e11a 100644 --- a/tests/baselines/reference/checkJsdocSatisfiesTag12.errors.txt +++ b/tests/baselines/reference/checkJsdocSatisfiesTag12.errors.txt @@ -2,7 +2,7 @@ Object literal may only specify known properties, and 'b' does not exist in type 'T1'. /a.js(44,25): error TS1360: Type '{ a: string; b: string; }' does not satisfy the expected type 'T2'. Object literal may only specify known properties, and 'b' does not exist in type 'T2'. -/a.js(51,17): error TS1360: Type 'number' does not satisfy the expected type 'string'. +/a.js(51,6): error TS1360: Type 'number' does not satisfy the expected type 'string'. ==== /a.js (3 errors) ==== @@ -63,6 +63,6 @@ const t7 = { a: "a" }; /** @satisfies {string} */ const t8 = (1); - ~~~~~~ + ~~~~~~~~~ !!! error TS1360: Type 'number' does not satisfy the expected type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/checkJsdocSatisfiesTag4.errors.txt b/tests/baselines/reference/checkJsdocSatisfiesTag4.errors.txt index 916671a213854..036fcfafc059b 100644 --- a/tests/baselines/reference/checkJsdocSatisfiesTag4.errors.txt +++ b/tests/baselines/reference/checkJsdocSatisfiesTag4.errors.txt @@ -1,4 +1,4 @@ -/a.js(5,32): error TS1360: Type '{}' does not satisfy the expected type 'Foo'. +/a.js(5,21): error TS1360: Type '{}' does not satisfy the expected type 'Foo'. Property 'a' is missing in type '{}' but required in type 'Foo'. @@ -8,7 +8,7 @@ * @property {number} a */ export default /** @satisfies {Foo} */ ({}); - ~~~ + ~~~~~~~~~ !!! error TS1360: Type '{}' does not satisfy the expected type 'Foo'. !!! error TS1360: Property 'a' is missing in type '{}' but required in type 'Foo'. !!! related TS2728 /a.js:3:4: 'a' is declared here. diff --git a/tests/baselines/reference/typeSatisfaction.errors.txt b/tests/baselines/reference/typeSatisfaction.errors.txt index c124d009a4bfd..d3ec6707b97cf 100644 --- a/tests/baselines/reference/typeSatisfaction.errors.txt +++ b/tests/baselines/reference/typeSatisfaction.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction.ts(12,20): error TS1360: Type '{ a: number; b: number; }' does not satisfy the expected type 'I1'. Object literal may only specify known properties, and 'b' does not exist in type 'I1'. -tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction.ts(13,26): error TS1360: Type '{}' does not satisfy the expected type 'I1'. +tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction.ts(13,16): error TS1360: Type '{}' does not satisfy the expected type 'I1'. Property 'a' is missing in type '{}' but required in type 'I1'. tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction.ts(24,23): error TS1360: Type '{ a: string; b: string; }' does not satisfy the expected type 'A'. Object literal may only specify known properties, and 'b' does not exist in type 'A'. @@ -23,7 +23,7 @@ tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction.ts(24,23): !!! error TS1360: Type '{ a: number; b: number; }' does not satisfy the expected type 'I1'. !!! error TS1360: Object literal may only specify known properties, and 'b' does not exist in type 'I1'. const t3 = { } satisfies I1; // Error - ~~ + ~~~~~~~~~ !!! error TS1360: Type '{}' does not satisfy the expected type 'I1'. !!! error TS1360: Property 'a' is missing in type '{}' but required in type 'I1'. !!! related TS2728 tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction.ts:2:5: 'a' is declared here. diff --git a/tests/baselines/reference/typeSatisfactionWithDefaultExport.errors.txt b/tests/baselines/reference/typeSatisfactionWithDefaultExport.errors.txt index f960726de5da9..4af8062dce0db 100644 --- a/tests/baselines/reference/typeSatisfactionWithDefaultExport.errors.txt +++ b/tests/baselines/reference/typeSatisfactionWithDefaultExport.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/expressions/typeSatisfaction/a.ts(4,29): error TS1360: Type '{}' does not satisfy the expected type 'Foo'. +tests/cases/conformance/expressions/typeSatisfaction/a.ts(4,19): error TS1360: Type '{}' does not satisfy the expected type 'Foo'. Property 'a' is missing in type '{}' but required in type 'Foo'. @@ -7,7 +7,7 @@ tests/cases/conformance/expressions/typeSatisfaction/a.ts(4,29): error TS1360: T a: number; } export default {} satisfies Foo; - ~~~ + ~~~~~~~~~ !!! error TS1360: Type '{}' does not satisfy the expected type 'Foo'. !!! error TS1360: Property 'a' is missing in type '{}' but required in type 'Foo'. !!! related TS2728 tests/cases/conformance/expressions/typeSatisfaction/a.ts:2:5: 'a' is declared here.