mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Report assignability errors on the satisfies keyword (#53797)
This commit is contained in:
parent
bdcf8abb0c
commit
5897d7a135
@ -34618,7 +34618,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;
|
||||
}
|
||||
|
||||
|
||||
@ -350,6 +350,7 @@ import {
|
||||
JSDocParameterTag,
|
||||
JSDocPropertyLikeTag,
|
||||
JSDocSatisfiesExpression,
|
||||
JSDocSatisfiesTag,
|
||||
JSDocSignature,
|
||||
JSDocTag,
|
||||
JSDocTemplateTag,
|
||||
@ -2234,6 +2235,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) {
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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'.
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user