Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10703,8 +10703,7 @@ func (c *Checker) checkSatisfiesExpression(node *ast.Node) *Type {
if c.isErrorType(targetType) {
return targetType
}
errorNode := core.IfElse(typeNode.Flags&ast.NodeFlagsReparsed != 0, typeNode, node)
c.checkTypeAssignableToAndOptionallyElaborate(exprType, targetType, errorNode, node.Expression(), diagnostics.Type_0_does_not_satisfy_the_expected_type_1, nil)
c.checkTypeAssignableToAndOptionallyElaborate(exprType, targetType, node, node.Expression(), diagnostics.Type_0_does_not_satisfy_the_expected_type_1, nil)
return exprType
}

Expand Down
40 changes: 36 additions & 4 deletions internal/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2514,6 +2514,38 @@ func getErrorRangeForArrowFunction(sourceFile *ast.SourceFile, node *ast.Node) c
return core.NewTextRange(pos, node.End())
}

func findOriginatingJSDocSatisfiesTag(sourceFile *ast.SourceFile, node *ast.Node) *ast.Node {
targetType := node.AsSatisfiesExpression().Type
if targetType.Flags&ast.NodeFlagsReparsed == 0 {
return nil
}
for current := node.Parent; current != nil; current = current.Parent {
if current.Flags&ast.NodeFlagsHasJSDoc == 0 {
continue
}
var firstSatisfiesTag *ast.Node
for _, jsDoc := range current.EagerJSDoc(sourceFile) {
if tags := jsDoc.AsJSDoc().Tags; tags != nil {
for _, tag := range tags.Nodes {
if !ast.IsJSDocSatisfiesTag(tag) {
continue
}
if firstSatisfiesTag == nil {
firstSatisfiesTag = tag
}
if typeExpr := tag.AsJSDocSatisfiesTag().TypeExpression; typeExpr != nil {
if t := typeExpr.Type(); t != nil && t.Loc == targetType.Loc {
return tag
}
}
}
}
}
return firstSatisfiesTag
}
return nil
}

func GetErrorRangeForNode(sourceFile *ast.SourceFile, node *ast.Node) core.TextRange {
errorNode := node
switch node.Kind {
Expand Down Expand Up @@ -2552,6 +2584,10 @@ func GetErrorRangeForNode(sourceFile *ast.SourceFile, node *ast.Node) core.TextR
pos := SkipTrivia(sourceFile.Text(), node.Pos())
return GetRangeOfTokenAtPosition(sourceFile, pos)
case ast.KindSatisfiesExpression:
if jsDocSatisfiesTag := findOriginatingJSDocSatisfiesTag(sourceFile, node); jsDocSatisfiesTag != nil {
pos := SkipTrivia(sourceFile.Text(), jsDocSatisfiesTag.TagName().Pos())
return GetRangeOfTokenAtPosition(sourceFile, pos)
}
pos := SkipTrivia(sourceFile.Text(), node.AsSatisfiesExpression().Expression.End())
return GetRangeOfTokenAtPosition(sourceFile, pos)
case ast.KindConstructor:
Expand All @@ -2565,10 +2601,6 @@ func GetErrorRangeForNode(sourceFile *ast.SourceFile, node *ast.Node) core.TextR
scanner.Scan()
}
return core.NewTextRange(start, scanner.TokenEnd())
// !!!
// case KindJSDocSatisfiesTag:
// pos := scanner.SkipTrivia(sourceFile.Text(), node.tagName.pos)
// return scanner.GetRangeOfTokenAtPosition(sourceFile, pos)
}
if errorNode == nil {
// If we don't have a better node, then just set the error on the first token of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/a.js(9,16): error TS1360: Type '(a: string, b: string) => void' does not satisfy the expected type '(a: string, ...args: number[]) => void'.
/a.js(9,5): error TS1360: Type '(a: string, b: string) => void' does not satisfy the expected type '(a: string, ...args: number[]) => void'.
Types of parameters 'b' and 'args' are incompatible.
Type 'number' is not assignable to type 'string'.

Expand All @@ -13,7 +13,7 @@

/**
* @satisfies {(a: string, ...args: number[]) => void}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~
!!! error TS1360: Type '(a: string, b: string) => void' does not satisfy the expected type '(a: string, ...args: number[]) => void'.
!!! error TS1360: Types of parameters 'b' and 'args' are incompatible.
!!! error TS1360: Type 'number' is not assignable to type 'string'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/a.js(21,44): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type 'T1'.
/a.js(22,28): error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
/a.js(22,17): error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
/a.js(31,49): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type 'T4'.


Expand Down Expand Up @@ -28,7 +28,7 @@
~
!!! error TS2353: Object literal may only specify known properties, and 'b' does not exist in type 'T1'.
const t3 = /** @satisfies {T1} */ ({});
~~
~~~~~~~~~
!!! error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
!!! related TS2728 /a.js:3:23: 'a' is declared here.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
/a.js(21,44): error TS2353: Object literal may only specify known properties, and 'b' does not exist in 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(22,28): error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
+/a.js(22,17): error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
/a.js(31,49): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type 'T4'.


@@= skipped -28, +27 lines =@@
~
@@= skipped -29, +28 lines =@@
!!! error TS2353: 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.
+ ~~
+!!! error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
+!!! related TS2728 /a.js:3:23: 'a' is declared here.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/a.js(24,20): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type 'T1'.
/a.js(27,16): error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
/a.js(27,5): error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
/a.js(44,25): error TS2353: 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 (4 errors) ====
Expand Down Expand Up @@ -34,7 +34,7 @@

/**
* @satisfies {T1}
~~
~~~~~~~~~
!!! error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
!!! related TS2728 /a.js:3:23: 'a' is declared here.
*/
Expand Down Expand Up @@ -63,6 +63,6 @@
const t7 = { a: "a" };

/** @satisfies {string} */ const t8 = (1);
~~~~~~
~~~~~~~~~
!!! error TS1360: Type 'number' does not satisfy the expected type 'string'.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
+++ new.checkJsdocSatisfiesTag12.errors.txt
@@= skipped -0, +0 lines =@@
/a.js(24,20): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type 'T1'.
+/a.js(27,16): error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
+/a.js(27,5): error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
/a.js(44,25): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type 'T2'.
-/a.js(51,6): 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) ====
+/a.js(51,17): error TS1360: Type 'number' does not satisfy the expected type 'string'.
+
+
+==== /a.js (4 errors) ====
/**
* @typedef {Object} T1
Expand All @@ -19,17 +16,9 @@

/**
* @satisfies {T1}
+ ~~
+ ~~~~~~~~~
+!!! error TS2741: Property 'a' is missing in type '{}' but required in type 'T1'.
+!!! related TS2728 /a.js:3:23: 'a' is declared here.
*/
const t3 = {};

@@= skipped -26, +29 lines =@@
const t7 = { a: "a" };

/** @satisfies {string} */ const t8 = (1);
- ~~~~~~~~~
+ ~~~~~~
!!! error TS1360: Type 'number' does not satisfy the expected type 'string'.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/a.js(9,20): error TS2322: Type 'number' is not assignable to type 'string'.
/a.js(28,16): error TS1360: Type '(a: string, b: string) => void' does not satisfy the expected type '(a: string, ...args: number[]) => void'.
/a.js(28,5): error TS1360: Type '(a: string, b: string) => void' does not satisfy the expected type '(a: string, ...args: number[]) => void'.
Types of parameters 'b' and 'args' are incompatible.
Type 'number' is not assignable to type 'string'.
/a.js(42,21): error TS7006: Parameter 'uuid' implicitly has an 'any' type.
Expand Down Expand Up @@ -36,7 +36,7 @@

/**
* @satisfies {(a: string, ...args: number[]) => void}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~
!!! error TS1360: Type '(a: string, b: string) => void' does not satisfy the expected type '(a: string, ...args: number[]) => void'.
!!! error TS1360: Types of parameters 'b' and 'args' are incompatible.
!!! error TS1360: Type 'number' is not assignable to type 'string'.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/a.js(5,32): error TS2741: Property 'a' is missing in type '{}' but required in type 'Foo'.
/a.js(5,21): error TS2741: Property 'a' is missing in type '{}' but required in type 'Foo'.


==== /a.js (1 errors) ====
Expand All @@ -7,7 +7,7 @@
* @property {number} a
*/
export default /** @satisfies {Foo} */ ({});
~~~
~~~~~~~~~
!!! error TS2741: Property 'a' is missing in type '{}' but required in type 'Foo'.
!!! related TS2728 /a.js:3:23: 'a' is declared here.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
@@= skipped -0, +0 lines =@@
-/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'.
+/a.js(5,32): error TS2741: Property 'a' is missing in type '{}' but required in type 'Foo'.
+/a.js(5,21): error TS2741: Property 'a' is missing in type '{}' but required in type 'Foo'.


==== /a.js (1 errors) ====
@@= skipped -7, +6 lines =@@
* @property {number} a
@@= skipped -8, +7 lines =@@
*/
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.
+ ~~~
+!!! error TS2741: Property 'a' is missing in type '{}' but required in type 'Foo'.
+!!! related TS2728 /a.js:3:23: 'a' is declared here.

Expand Down
Loading