diff --git a/internal/ast/ast.go b/internal/ast/ast.go index 741e753bc7..87e9c79c53 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -2125,6 +2125,7 @@ type FunctionLikeBase struct { TypeParameters *NodeList // NodeList[*TypeParameterDeclarationNode]. Optional Parameters *NodeList // NodeList[*ParameterDeclarationNode] Type *TypeNode // Optional + FullSignature *TypeNode // Type that applies to the whole function; should not be set if Type is set or if Parameters have types set. } func (node *FunctionLikeBase) LocalsContainerData() *LocalsContainerBase { @@ -3703,7 +3704,7 @@ type FunctionDeclaration struct { ReturnFlowNode *FlowNode } -func (f *NodeFactory) NewFunctionDeclaration(modifiers *ModifierList, asteriskToken *TokenNode, name *IdentifierNode, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, body *BlockNode) *Node { +func (f *NodeFactory) NewFunctionDeclaration(modifiers *ModifierList, asteriskToken *TokenNode, name *IdentifierNode, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { data := f.functionDeclarationPool.New() data.modifiers = modifiers data.AsteriskToken = asteriskToken @@ -3711,28 +3712,29 @@ func (f *NodeFactory) NewFunctionDeclaration(modifiers *ModifierList, asteriskTo data.TypeParameters = typeParameters data.Parameters = parameters data.Type = returnType + data.FullSignature = fullSignature data.Body = body return f.newNode(KindFunctionDeclaration, data) } -func (f *NodeFactory) UpdateFunctionDeclaration(node *FunctionDeclaration, modifiers *ModifierList, asteriskToken *TokenNode, name *IdentifierNode, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, body *BlockNode) *Node { - if modifiers != node.modifiers || asteriskToken != node.AsteriskToken || name != node.name || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || body != node.Body { - return updateNode(f.NewFunctionDeclaration(modifiers, asteriskToken, name, typeParameters, parameters, returnType, body), node.AsNode(), f.hooks) +func (f *NodeFactory) UpdateFunctionDeclaration(node *FunctionDeclaration, modifiers *ModifierList, asteriskToken *TokenNode, name *IdentifierNode, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { + if modifiers != node.modifiers || asteriskToken != node.AsteriskToken || name != node.name || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || fullSignature != node.FullSignature || body != node.Body { + return updateNode(f.NewFunctionDeclaration(modifiers, asteriskToken, name, typeParameters, parameters, returnType, fullSignature, body), node.AsNode(), f.hooks) } return node.AsNode() } func (node *FunctionDeclaration) ForEachChild(v Visitor) bool { return visitModifiers(v, node.modifiers) || visit(v, node.AsteriskToken) || visit(v, node.name) || visitNodeList(v, node.TypeParameters) || - visitNodeList(v, node.Parameters) || visit(v, node.Type) || visit(v, node.Body) + visitNodeList(v, node.Parameters) || visit(v, node.Type) || visit(v, node.FullSignature) || visit(v, node.Body) } func (node *FunctionDeclaration) VisitEachChild(v *NodeVisitor) *Node { - return v.Factory.UpdateFunctionDeclaration(node, v.visitModifiers(node.modifiers), v.visitToken(node.AsteriskToken), v.visitNode(node.name), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitFunctionBody(node.Body)) + return v.Factory.UpdateFunctionDeclaration(node, v.visitModifiers(node.modifiers), v.visitToken(node.AsteriskToken), v.visitNode(node.name), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitNode(node.FullSignature), v.visitFunctionBody(node.Body)) } func (node *FunctionDeclaration) Clone(f NodeFactoryCoercible) *Node { - return cloneNode(f.AsNodeFactory().NewFunctionDeclaration(node.Modifiers(), node.AsteriskToken, node.Name(), node.TypeParameters, node.Parameters, node.Type, node.Body), node.AsNode(), f.AsNodeFactory().hooks) + return cloneNode(f.AsNodeFactory().NewFunctionDeclaration(node.Modifiers(), node.AsteriskToken, node.Name(), node.TypeParameters, node.Parameters, node.Type, node.FullSignature, node.Body), node.AsNode(), f.AsNodeFactory().hooks) } func (node *FunctionDeclaration) Name() *DeclarationName { @@ -3751,6 +3753,7 @@ func (node *FunctionDeclaration) computeSubtreeFacts() SubtreeFacts { propagateEraseableSyntaxListSubtreeFacts(node.TypeParameters) | propagateNodeListSubtreeFacts(node.Parameters, propagateSubtreeFacts) | propagateEraseableSyntaxSubtreeFacts(node.Type) | + propagateEraseableSyntaxSubtreeFacts(node.FullSignature) | propagateSubtreeFacts(node.Body) | core.IfElse(isAsync && isGenerator, SubtreeContainsForAwaitOrAsyncGenerator, SubtreeFactsNone) | core.IfElse(isAsync && !isGenerator, SubtreeContainsAnyAwait, SubtreeFactsNone) @@ -5196,33 +5199,34 @@ type ConstructorDeclaration struct { ReturnFlowNode *FlowNode } -func (f *NodeFactory) NewConstructorDeclaration(modifiers *ModifierList, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, body *BlockNode) *Node { +func (f *NodeFactory) NewConstructorDeclaration(modifiers *ModifierList, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { data := &ConstructorDeclaration{} data.modifiers = modifiers data.TypeParameters = typeParameters data.Parameters = parameters data.Type = returnType + data.FullSignature = fullSignature data.Body = body return f.newNode(KindConstructor, data) } -func (f *NodeFactory) UpdateConstructorDeclaration(node *ConstructorDeclaration, modifiers *ModifierList, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, body *BlockNode) *Node { - if modifiers != node.modifiers || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || body != node.Body { - return updateNode(f.NewConstructorDeclaration(modifiers, typeParameters, parameters, returnType, body), node.AsNode(), f.hooks) +func (f *NodeFactory) UpdateConstructorDeclaration(node *ConstructorDeclaration, modifiers *ModifierList, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { + if modifiers != node.modifiers || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || fullSignature != node.FullSignature || body != node.Body { + return updateNode(f.NewConstructorDeclaration(modifiers, typeParameters, parameters, returnType, fullSignature, body), node.AsNode(), f.hooks) } return node.AsNode() } func (node *ConstructorDeclaration) ForEachChild(v Visitor) bool { - return visitModifiers(v, node.modifiers) || visitNodeList(v, node.TypeParameters) || visitNodeList(v, node.Parameters) || visit(v, node.Type) || visit(v, node.Body) + return visitModifiers(v, node.modifiers) || visitNodeList(v, node.TypeParameters) || visitNodeList(v, node.Parameters) || visit(v, node.Type) || visit(v, node.FullSignature) || visit(v, node.Body) } func (node *ConstructorDeclaration) VisitEachChild(v *NodeVisitor) *Node { - return v.Factory.UpdateConstructorDeclaration(node, v.visitModifiers(node.modifiers), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitFunctionBody(node.Body)) + return v.Factory.UpdateConstructorDeclaration(node, v.visitModifiers(node.modifiers), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitNode(node.FullSignature), v.visitFunctionBody(node.Body)) } func (node *ConstructorDeclaration) Clone(f NodeFactoryCoercible) *Node { - return cloneNode(f.AsNodeFactory().NewConstructorDeclaration(node.Modifiers(), node.TypeParameters, node.Parameters, node.Type, node.Body), node.AsNode(), f.AsNodeFactory().hooks) + return cloneNode(f.AsNodeFactory().NewConstructorDeclaration(node.Modifiers(), node.TypeParameters, node.Parameters, node.Type, node.FullSignature, node.Body), node.AsNode(), f.AsNodeFactory().hooks) } func (node *ConstructorDeclaration) computeSubtreeFacts() SubtreeFacts { @@ -5233,6 +5237,7 @@ func (node *ConstructorDeclaration) computeSubtreeFacts() SubtreeFacts { propagateEraseableSyntaxListSubtreeFacts(node.TypeParameters) | propagateNodeListSubtreeFacts(node.Parameters, propagateSubtreeFacts) | propagateEraseableSyntaxSubtreeFacts(node.Type) | + propagateEraseableSyntaxSubtreeFacts(node.FullSignature) | propagateSubtreeFacts(node.Body) } } @@ -5260,7 +5265,7 @@ type AccessorDeclarationBase struct { func (node *AccessorDeclarationBase) ForEachChild(v Visitor) bool { return visitModifiers(v, node.modifiers) || visit(v, node.name) || visitNodeList(v, node.TypeParameters) || visitNodeList(v, node.Parameters) || - visit(v, node.Type) || visit(v, node.Body) + visit(v, node.Type) || visit(v, node.FullSignature) || visit(v, node.Body) } func (node *AccessorDeclarationBase) IsAccessorDeclaration() {} @@ -5274,6 +5279,7 @@ func (node *AccessorDeclarationBase) computeSubtreeFacts() SubtreeFacts { propagateEraseableSyntaxListSubtreeFacts(node.TypeParameters) | propagateNodeListSubtreeFacts(node.Parameters, propagateSubtreeFacts) | propagateEraseableSyntaxSubtreeFacts(node.Type) | + propagateEraseableSyntaxSubtreeFacts(node.FullSignature) | propagateSubtreeFacts(node.Body) } } @@ -5289,30 +5295,31 @@ type GetAccessorDeclaration struct { AccessorDeclarationBase } -func (f *NodeFactory) NewGetAccessorDeclaration(modifiers *ModifierList, name *PropertyName, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, body *BlockNode) *Node { +func (f *NodeFactory) NewGetAccessorDeclaration(modifiers *ModifierList, name *PropertyName, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { data := &GetAccessorDeclaration{} data.modifiers = modifiers data.name = name data.TypeParameters = typeParameters data.Parameters = parameters data.Type = returnType + data.FullSignature = fullSignature data.Body = body return f.newNode(KindGetAccessor, data) } -func (f *NodeFactory) UpdateGetAccessorDeclaration(node *GetAccessorDeclaration, modifiers *ModifierList, name *PropertyName, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, body *BlockNode) *Node { - if modifiers != node.modifiers || name != node.name || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || body != node.Body { - return updateNode(f.NewGetAccessorDeclaration(modifiers, name, typeParameters, parameters, returnType, body), node.AsNode(), f.hooks) +func (f *NodeFactory) UpdateGetAccessorDeclaration(node *GetAccessorDeclaration, modifiers *ModifierList, name *PropertyName, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { + if modifiers != node.modifiers || name != node.name || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || fullSignature != node.FullSignature || body != node.Body { + return updateNode(f.NewGetAccessorDeclaration(modifiers, name, typeParameters, parameters, returnType, fullSignature, body), node.AsNode(), f.hooks) } return node.AsNode() } func (node *GetAccessorDeclaration) VisitEachChild(v *NodeVisitor) *Node { - return v.Factory.UpdateGetAccessorDeclaration(node, v.visitModifiers(node.modifiers), v.visitNode(node.name), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitFunctionBody(node.Body)) + return v.Factory.UpdateGetAccessorDeclaration(node, v.visitModifiers(node.modifiers), v.visitNode(node.name), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitNode(node.FullSignature), v.visitFunctionBody(node.Body)) } func (node *GetAccessorDeclaration) Clone(f NodeFactoryCoercible) *Node { - return cloneNode(f.AsNodeFactory().NewGetAccessorDeclaration(node.modifiers, node.Name(), node.TypeParameters, node.Parameters, node.Type, node.Body), node.AsNode(), f.AsNodeFactory().hooks) + return cloneNode(f.AsNodeFactory().NewGetAccessorDeclaration(node.modifiers, node.Name(), node.TypeParameters, node.Parameters, node.Type, node.FullSignature, node.Body), node.AsNode(), f.AsNodeFactory().hooks) } func IsGetAccessorDeclaration(node *Node) bool { @@ -5325,30 +5332,31 @@ type SetAccessorDeclaration struct { AccessorDeclarationBase } -func (f *NodeFactory) NewSetAccessorDeclaration(modifiers *ModifierList, name *PropertyName, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, body *BlockNode) *Node { +func (f *NodeFactory) NewSetAccessorDeclaration(modifiers *ModifierList, name *PropertyName, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { data := &SetAccessorDeclaration{} data.modifiers = modifiers data.name = name data.TypeParameters = typeParameters data.Parameters = parameters data.Type = returnType + data.FullSignature = fullSignature data.Body = body return f.newNode(KindSetAccessor, data) } -func (f *NodeFactory) UpdateSetAccessorDeclaration(node *SetAccessorDeclaration, modifiers *ModifierList, name *PropertyName, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, body *BlockNode) *Node { - if modifiers != node.modifiers || name != node.name || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || body != node.Body { - return updateNode(f.NewSetAccessorDeclaration(modifiers, name, typeParameters, parameters, returnType, body), node.AsNode(), f.hooks) +func (f *NodeFactory) UpdateSetAccessorDeclaration(node *SetAccessorDeclaration, modifiers *ModifierList, name *PropertyName, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { + if modifiers != node.modifiers || name != node.name || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || fullSignature != node.FullSignature || body != node.Body { + return updateNode(f.NewSetAccessorDeclaration(modifiers, name, typeParameters, parameters, returnType, fullSignature, body), node.AsNode(), f.hooks) } return node.AsNode() } func (node *SetAccessorDeclaration) VisitEachChild(v *NodeVisitor) *Node { - return v.Factory.UpdateSetAccessorDeclaration(node, v.visitModifiers(node.modifiers), v.visitNode(node.name), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitFunctionBody(node.Body)) + return v.Factory.UpdateSetAccessorDeclaration(node, v.visitModifiers(node.modifiers), v.visitNode(node.name), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitNode(node.FullSignature), v.visitFunctionBody(node.Body)) } func (node *SetAccessorDeclaration) Clone(f NodeFactoryCoercible) *Node { - return cloneNode(f.AsNodeFactory().NewSetAccessorDeclaration(node.Modifiers(), node.Name(), node.TypeParameters, node.Parameters, node.Type, node.Body), node.AsNode(), f.AsNodeFactory().hooks) + return cloneNode(f.AsNodeFactory().NewSetAccessorDeclaration(node.Modifiers(), node.Name(), node.TypeParameters, node.Parameters, node.Type, node.FullSignature, node.Body), node.AsNode(), f.AsNodeFactory().hooks) } func IsSetAccessorDeclaration(node *Node) bool { @@ -5455,7 +5463,7 @@ type MethodDeclaration struct { compositeNodeBase } -func (f *NodeFactory) NewMethodDeclaration(modifiers *ModifierList, asteriskToken *TokenNode, name *PropertyName, postfixToken *TokenNode, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, body *BlockNode) *Node { +func (f *NodeFactory) NewMethodDeclaration(modifiers *ModifierList, asteriskToken *TokenNode, name *PropertyName, postfixToken *TokenNode, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { data := &MethodDeclaration{} data.modifiers = modifiers data.AsteriskToken = asteriskToken @@ -5464,28 +5472,29 @@ func (f *NodeFactory) NewMethodDeclaration(modifiers *ModifierList, asteriskToke data.TypeParameters = typeParameters data.Parameters = parameters data.Type = returnType + data.FullSignature = fullSignature data.Body = body return f.newNode(KindMethodDeclaration, data) } -func (f *NodeFactory) UpdateMethodDeclaration(node *MethodDeclaration, modifiers *ModifierList, asteriskToken *TokenNode, name *PropertyName, postfixToken *TokenNode, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, body *BlockNode) *Node { - if modifiers != node.modifiers || asteriskToken != node.AsteriskToken || name != node.name || postfixToken != node.PostfixToken || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || body != node.Body { - return updateNode(f.NewMethodDeclaration(modifiers, asteriskToken, name, postfixToken, typeParameters, parameters, returnType, body), node.AsNode(), f.hooks) +func (f *NodeFactory) UpdateMethodDeclaration(node *MethodDeclaration, modifiers *ModifierList, asteriskToken *TokenNode, name *PropertyName, postfixToken *TokenNode, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { + if modifiers != node.modifiers || asteriskToken != node.AsteriskToken || name != node.name || postfixToken != node.PostfixToken || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || fullSignature != node.FullSignature || body != node.Body { + return updateNode(f.NewMethodDeclaration(modifiers, asteriskToken, name, postfixToken, typeParameters, parameters, returnType, fullSignature, body), node.AsNode(), f.hooks) } return node.AsNode() } func (node *MethodDeclaration) ForEachChild(v Visitor) bool { return visitModifiers(v, node.modifiers) || visit(v, node.AsteriskToken) || visit(v, node.name) || visit(v, node.PostfixToken) || - visitNodeList(v, node.TypeParameters) || visitNodeList(v, node.Parameters) || visit(v, node.Type) || visit(v, node.Body) + visitNodeList(v, node.TypeParameters) || visitNodeList(v, node.Parameters) || visit(v, node.Type) || visit(v, node.FullSignature) || visit(v, node.Body) } func (node *MethodDeclaration) VisitEachChild(v *NodeVisitor) *Node { - return v.Factory.UpdateMethodDeclaration(node, v.visitModifiers(node.modifiers), v.visitToken(node.AsteriskToken), v.visitNode(node.name), v.visitToken(node.PostfixToken), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitFunctionBody(node.Body)) + return v.Factory.UpdateMethodDeclaration(node, v.visitModifiers(node.modifiers), v.visitToken(node.AsteriskToken), v.visitNode(node.name), v.visitToken(node.PostfixToken), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitNode(node.FullSignature), v.visitFunctionBody(node.Body)) } func (node *MethodDeclaration) Clone(f NodeFactoryCoercible) *Node { - return cloneNode(f.AsNodeFactory().NewMethodDeclaration(node.Modifiers(), node.AsteriskToken, node.Name(), node.PostfixToken, node.TypeParameters, node.Parameters, node.Type, node.Body), node.AsNode(), f.AsNodeFactory().hooks) + return cloneNode(f.AsNodeFactory().NewMethodDeclaration(node.Modifiers(), node.AsteriskToken, node.Name(), node.PostfixToken, node.TypeParameters, node.Parameters, node.Type, node.FullSignature, node.Body), node.AsNode(), f.AsNodeFactory().hooks) } func (node *MethodDeclaration) computeSubtreeFacts() SubtreeFacts { @@ -5502,6 +5511,7 @@ func (node *MethodDeclaration) computeSubtreeFacts() SubtreeFacts { propagateNodeListSubtreeFacts(node.Parameters, propagateSubtreeFacts) | propagateSubtreeFacts(node.Body) | propagateEraseableSyntaxSubtreeFacts(node.Type) | + propagateEraseableSyntaxSubtreeFacts(node.FullSignature) | core.IfElse(isAsync && isGenerator, SubtreeContainsForAwaitOrAsyncGenerator, SubtreeFactsNone) | core.IfElse(isAsync && !isGenerator, SubtreeContainsAnyAwait, SubtreeFactsNone) } @@ -6044,35 +6054,36 @@ type ArrowFunction struct { EqualsGreaterThanToken *TokenNode // TokenNode } -func (f *NodeFactory) NewArrowFunction(modifiers *ModifierList, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, equalsGreaterThanToken *TokenNode, body *BlockOrExpression) *Node { +func (f *NodeFactory) NewArrowFunction(modifiers *ModifierList, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, fullSignature *TypeNode, equalsGreaterThanToken *TokenNode, body *BlockOrExpression) *Node { data := &ArrowFunction{} data.modifiers = modifiers data.TypeParameters = typeParameters data.Parameters = parameters data.Type = returnType + data.FullSignature = fullSignature data.EqualsGreaterThanToken = equalsGreaterThanToken data.Body = body return f.newNode(KindArrowFunction, data) } -func (f *NodeFactory) UpdateArrowFunction(node *ArrowFunction, modifiers *ModifierList, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, equalsGreaterThanToken *TokenNode, body *BlockOrExpression) *Node { - if modifiers != node.modifiers || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || equalsGreaterThanToken != node.EqualsGreaterThanToken || body != node.Body { - return updateNode(f.NewArrowFunction(modifiers, typeParameters, parameters, returnType, equalsGreaterThanToken, body), node.AsNode(), f.hooks) +func (f *NodeFactory) UpdateArrowFunction(node *ArrowFunction, modifiers *ModifierList, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, fullSignature *TypeNode, equalsGreaterThanToken *TokenNode, body *BlockOrExpression) *Node { + if modifiers != node.modifiers || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || fullSignature != node.FullSignature || equalsGreaterThanToken != node.EqualsGreaterThanToken || body != node.Body { + return updateNode(f.NewArrowFunction(modifiers, typeParameters, parameters, returnType, fullSignature, equalsGreaterThanToken, body), node.AsNode(), f.hooks) } return node.AsNode() } func (node *ArrowFunction) ForEachChild(v Visitor) bool { return visitModifiers(v, node.modifiers) || visitNodeList(v, node.TypeParameters) || visitNodeList(v, node.Parameters) || - visit(v, node.Type) || visit(v, node.EqualsGreaterThanToken) || visit(v, node.Body) + visit(v, node.Type) || visit(v, node.FullSignature) || visit(v, node.EqualsGreaterThanToken) || visit(v, node.Body) } func (node *ArrowFunction) VisitEachChild(v *NodeVisitor) *Node { - return v.Factory.UpdateArrowFunction(node, v.visitModifiers(node.modifiers), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitToken(node.EqualsGreaterThanToken), v.visitFunctionBody(node.Body)) + return v.Factory.UpdateArrowFunction(node, v.visitModifiers(node.modifiers), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitNode(node.FullSignature), v.visitToken(node.EqualsGreaterThanToken), v.visitFunctionBody(node.Body)) } func (node *ArrowFunction) Clone(f NodeFactoryCoercible) *Node { - return cloneNode(f.AsNodeFactory().NewArrowFunction(node.Modifiers(), node.TypeParameters, node.Parameters, node.Type, node.EqualsGreaterThanToken, node.Body), node.AsNode(), f.AsNodeFactory().hooks) + return cloneNode(f.AsNodeFactory().NewArrowFunction(node.Modifiers(), node.TypeParameters, node.Parameters, node.Type, node.FullSignature, node.EqualsGreaterThanToken, node.Body), node.AsNode(), f.AsNodeFactory().hooks) } func (node *ArrowFunction) Name() *DeclarationName { @@ -6084,6 +6095,7 @@ func (node *ArrowFunction) computeSubtreeFacts() SubtreeFacts { propagateEraseableSyntaxListSubtreeFacts(node.TypeParameters) | propagateNodeListSubtreeFacts(node.Parameters, propagateSubtreeFacts) | propagateEraseableSyntaxSubtreeFacts(node.Type) | + propagateEraseableSyntaxSubtreeFacts(node.FullSignature) | propagateSubtreeFacts(node.Body) | core.IfElse(node.ModifierFlags()&ModifierFlagsAsync != 0, SubtreeContainsAnyAwait, SubtreeFactsNone) } @@ -6109,7 +6121,7 @@ type FunctionExpression struct { ReturnFlowNode *FlowNode } -func (f *NodeFactory) NewFunctionExpression(modifiers *ModifierList, asteriskToken *TokenNode, name *IdentifierNode, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, body *BlockNode) *Node { +func (f *NodeFactory) NewFunctionExpression(modifiers *ModifierList, asteriskToken *TokenNode, name *IdentifierNode, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { data := &FunctionExpression{} data.modifiers = modifiers data.AsteriskToken = asteriskToken @@ -6117,28 +6129,29 @@ func (f *NodeFactory) NewFunctionExpression(modifiers *ModifierList, asteriskTok data.TypeParameters = typeParameters data.Parameters = parameters data.Type = returnType + data.FullSignature = fullSignature data.Body = body return f.newNode(KindFunctionExpression, data) } -func (f *NodeFactory) UpdateFunctionExpression(node *FunctionExpression, modifiers *ModifierList, asteriskToken *TokenNode, name *IdentifierNode, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, body *BlockNode) *Node { - if modifiers != node.modifiers || asteriskToken != node.AsteriskToken || name != node.name || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || body != node.Body { - return updateNode(f.NewFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, returnType, body), node.AsNode(), f.hooks) +func (f *NodeFactory) UpdateFunctionExpression(node *FunctionExpression, modifiers *ModifierList, asteriskToken *TokenNode, name *IdentifierNode, typeParameters *TypeParameterList, parameters *ParameterList, returnType *TypeNode, fullSignature *TypeNode, body *BlockNode) *Node { + if modifiers != node.modifiers || asteriskToken != node.AsteriskToken || name != node.name || typeParameters != node.TypeParameters || parameters != node.Parameters || returnType != node.Type || fullSignature != node.FullSignature || body != node.Body { + return updateNode(f.NewFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, returnType, fullSignature, body), node.AsNode(), f.hooks) } return node.AsNode() } func (node *FunctionExpression) ForEachChild(v Visitor) bool { return visitModifiers(v, node.modifiers) || visit(v, node.AsteriskToken) || visit(v, node.name) || visitNodeList(v, node.TypeParameters) || - visitNodeList(v, node.Parameters) || visit(v, node.Type) || visit(v, node.Body) + visitNodeList(v, node.Parameters) || visit(v, node.Type) || visit(v, node.FullSignature) || visit(v, node.Body) } func (node *FunctionExpression) VisitEachChild(v *NodeVisitor) *Node { - return v.Factory.UpdateFunctionExpression(node, v.visitModifiers(node.modifiers), v.visitToken(node.AsteriskToken), v.visitNode(node.name), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitFunctionBody(node.Body)) + return v.Factory.UpdateFunctionExpression(node, v.visitModifiers(node.modifiers), v.visitToken(node.AsteriskToken), v.visitNode(node.name), v.visitNodes(node.TypeParameters), v.visitParameters(node.Parameters), v.visitNode(node.Type), v.visitNode(node.FullSignature), v.visitFunctionBody(node.Body)) } func (node *FunctionExpression) Clone(f NodeFactoryCoercible) *Node { - return cloneNode(f.AsNodeFactory().NewFunctionExpression(node.Modifiers(), node.AsteriskToken, node.Name(), node.TypeParameters, node.Parameters, node.Type, node.Body), node.AsNode(), f.AsNodeFactory().hooks) + return cloneNode(f.AsNodeFactory().NewFunctionExpression(node.Modifiers(), node.AsteriskToken, node.Name(), node.TypeParameters, node.Parameters, node.Type, node.FullSignature, node.Body), node.AsNode(), f.AsNodeFactory().hooks) } func (node *FunctionExpression) Name() *DeclarationName { @@ -6154,6 +6167,7 @@ func (node *FunctionExpression) computeSubtreeFacts() SubtreeFacts { propagateEraseableSyntaxListSubtreeFacts(node.TypeParameters) | propagateNodeListSubtreeFacts(node.Parameters, propagateSubtreeFacts) | propagateEraseableSyntaxSubtreeFacts(node.Type) | + propagateEraseableSyntaxSubtreeFacts(node.FullSignature) | propagateSubtreeFacts(node.Body) | core.IfElse(isAsync && isGenerator, SubtreeContainsForAwaitOrAsyncGenerator, SubtreeFactsNone) | core.IfElse(isAsync && !isGenerator, SubtreeContainsAnyAwait, SubtreeFactsNone) diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index 1241847cac..b34fa3d51f 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -3281,6 +3281,7 @@ func ReplaceModifiers(factory *NodeFactory, node *Node, modifierArray *ModifierL node.TypeParameterList(), node.ParameterList(), node.Type(), + node.AsMethodDeclaration().FullSignature, node.Body(), ) case KindConstructor: @@ -3290,6 +3291,7 @@ func ReplaceModifiers(factory *NodeFactory, node *Node, modifierArray *ModifierL node.TypeParameterList(), node.ParameterList(), node.Type(), + node.AsConstructorDeclaration().FullSignature, node.Body(), ) case KindGetAccessor: @@ -3300,6 +3302,7 @@ func ReplaceModifiers(factory *NodeFactory, node *Node, modifierArray *ModifierL node.TypeParameterList(), node.ParameterList(), node.Type(), + node.AsGetAccessorDeclaration().FullSignature, node.Body(), ) case KindSetAccessor: @@ -3310,6 +3313,7 @@ func ReplaceModifiers(factory *NodeFactory, node *Node, modifierArray *ModifierL node.TypeParameterList(), node.ParameterList(), node.Type(), + node.AsSetAccessorDeclaration().FullSignature, node.Body(), ) case KindIndexSignature: @@ -3328,6 +3332,7 @@ func ReplaceModifiers(factory *NodeFactory, node *Node, modifierArray *ModifierL node.TypeParameterList(), node.ParameterList(), node.Type(), + node.AsFunctionExpression().FullSignature, node.Body(), ) case KindArrowFunction: @@ -3337,6 +3342,7 @@ func ReplaceModifiers(factory *NodeFactory, node *Node, modifierArray *ModifierL node.TypeParameterList(), node.ParameterList(), node.Type(), + node.AsArrowFunction().FullSignature, node.AsArrowFunction().EqualsGreaterThanToken, node.Body(), ) @@ -3364,6 +3370,7 @@ func ReplaceModifiers(factory *NodeFactory, node *Node, modifierArray *ModifierL node.TypeParameterList(), node.ParameterList(), node.Type(), + node.AsFunctionDeclaration().FullSignature, node.Body(), ) case KindClassDeclaration: diff --git a/internal/checker/checker.go b/internal/checker/checker.go index fd724d90e8..241e0cdd06 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -3241,6 +3241,14 @@ func (c *Checker) checkFunctionOrMethodDeclaration(node *ast.Node) { body := node.Body() c.checkSourceElement(body) c.checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, c.getReturnTypeFromAnnotation(node)) + if node.FunctionLikeData().FullSignature != nil { + if c.getContextualCallSignature(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature), node) == nil { + c.error(node.FunctionLikeData().FullSignature, diagnostics.A_JSDoc_type_tag_on_a_function_must_have_a_signature_with_the_correct_number_of_arguments) + } + if node.Type() != nil || core.Some(node.Parameters(), func(p *ast.Node) bool { return p.Type() != nil }) { + c.error(node.FunctionLikeData().FullSignature, diagnostics.A_JSDoc_type_tag_may_not_occur_with_a_param_or_returns_tag) + } + } if node.Type() == nil { // Report an implicit any error if there is no body, no explicit return type, and node is not a private method // in an ambient context @@ -3532,7 +3540,15 @@ func (c *Checker) checkAllCodePathsInNonVoidFunctionReturnOrThrow(fn *ast.Node, return } hasExplicitReturn := fn.Flags&ast.NodeFlagsHasExplicitReturn != 0 - errorNode := core.OrElse(fn.Type(), fn) + errorNode := fn.Type() + if errorNode == nil { + if data := fn.FunctionLikeData(); data != nil && data.FullSignature != nil { + errorNode = data.FullSignature + } + } + if errorNode == nil { + errorNode = fn + } switch { case t != nil && t.flags&TypeFlagsNever != 0: c.error(errorNode, diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point) @@ -9754,6 +9770,14 @@ func (c *Checker) checkFunctionExpressionOrObjectLiteralMethod(node *ast.Node, c if !hasGrammarError && ast.IsFunctionExpression(node) { c.checkGrammarForGenerator(node) } + if node.FunctionLikeData().FullSignature != nil { + if c.getContextualCallSignature(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature), node) == nil { + c.error(node.FunctionLikeData().FullSignature, diagnostics.A_JSDoc_type_tag_on_a_function_must_have_a_signature_with_the_correct_number_of_arguments) + } + if node.Type() != nil || core.Some(node.Parameters(), func(p *ast.Node) bool { return p.Type() != nil }) { + c.error(node.FunctionLikeData().FullSignature, diagnostics.A_JSDoc_type_tag_may_not_occur_with_a_param_or_returns_tag) + } + } c.contextuallyCheckFunctionExpressionOrObjectLiteralMethod(node, checkMode) return c.getTypeOfSymbol(c.getSymbolOfDeclaration(node)) } @@ -11593,6 +11617,11 @@ func (c *Checker) TryGetThisTypeAtEx(node *ast.Node, includeGlobalThis bool, con } if ast.IsFunctionLike(container) && (!c.isInParameterInitializerBeforeContainingFunction(node) || ast.GetThisParameter(container) != nil) { thisType := c.getThisTypeOfDeclaration(container) + if thisType == nil && ast.IsInJSFile(container) { + if sig := c.getSignatureOfFullSignatureType(container); sig != nil { + thisType = c.getThisTypeOfSignature(sig) + } + } // Note: a parameter initializer should refer to class-this unless function-this is explicitly annotated. // If this is a function in a JS file, it might be a class method. if thisType == nil { @@ -15935,6 +15964,9 @@ func (c *Checker) getTypeForVariableLikeDeclaration(declaration *ast.Node, inclu return c.getReturnTypeOfSignature(getterSignature) } } + if t := c.getParameterTypeOfFullSignature(fn, declaration); t != nil { + return t + } // Use contextual parameter type if one is available var t *Type if declaration.Symbol().Name == ast.InternalSymbolNameThis { @@ -18906,6 +18938,12 @@ func (c *Checker) getSignaturesOfSymbol(symbol *ast.Symbol) []*Signature { } // If this is a function or method declaration, get the signature from the @type tag for the sake of optional parameters. // Exclude contextually-typed kinds because we already apply the @type tag to the context, plus applying it here to the initializer would suppress checks that the two are compatible. + if ast.IsFunctionExpressionOrArrowFunction(decl) || ast.IsObjectLiteralMethod(decl) { + if sig := c.getSignatureOfFullSignatureType(decl); sig != nil { + result = append(result, sig) + continue + } + } result = append(result, c.getSignatureFromDeclaration(decl)) } return result @@ -18984,6 +19022,11 @@ func (c *Checker) getTypeParametersFromDeclaration(declaration *ast.Node) []*Typ for _, node := range declaration.TypeParameters() { result = core.AppendIfUnique(result, c.getDeclaredTypeOfTypeParameter(node.Symbol())) } + if len(result) == 0 && ast.IsFunctionDeclaration(declaration) { + if sig := c.getSignatureOfFullSignatureType(declaration); sig != nil { + return sig.TypeParameters() + } + } return result } @@ -19133,6 +19176,32 @@ func (c *Checker) getReturnTypeFromAnnotation(declaration *ast.Node) *Type { if ast.IsGetAccessorDeclaration(declaration) && c.hasBindableName(declaration) { return c.getAnnotatedAccessorType(ast.GetDeclarationOfKind(c.getSymbolOfDeclaration(declaration), ast.KindSetAccessor)) } + return c.getReturnTypeOfFullSignature(declaration) +} + +func (c *Checker) getSignatureOfFullSignatureType(node *ast.Node) *Signature { + if ast.IsInJSFile(node) && ast.IsFunctionLike(node) && node.FunctionLikeData().FullSignature != nil { + return c.getSingleCallSignature(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature)) + } + return nil +} + +func (c *Checker) getParameterTypeOfFullSignature(node *ast.Node, parameter *ast.ParameterDeclarationNode) *Type { + if signature := c.getSignatureOfFullSignatureType(node); signature != nil { + pos := slices.Index(node.Parameters(), parameter) + if parameter.AsParameterDeclaration().DotDotDotToken != nil { + return c.getRestTypeAtPosition(signature, pos, false /*readonly*/) + } else { + return c.getTypeAtPosition(signature, pos) + } + } + return nil +} + +func (c *Checker) getReturnTypeOfFullSignature(node *ast.Node) *Type { + if signature := c.getSignatureOfFullSignatureType(node); signature != nil { + return c.getReturnTypeOfSignature(signature) + } return nil } diff --git a/internal/checker/emitresolver.go b/internal/checker/emitresolver.go index 38a7812f65..5c3ec5e7c8 100644 --- a/internal/checker/emitresolver.go +++ b/internal/checker/emitresolver.go @@ -863,6 +863,18 @@ func (r *emitResolver) CreateReturnTypeOfSignatureDeclaration(emitContext *print return requestNodeBuilder.SerializeReturnTypeForSignature(original, enclosingDeclaration, flags, internalFlags, tracker) } +func (r *emitResolver) CreateTypeParametersOfSignatureDeclaration(emitContext *printer.EmitContext, signatureDeclaration *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) []*ast.Node { + original := emitContext.ParseNode(signatureDeclaration) + if original == nil { + return nil + } + + r.checkerMu.Lock() + defer r.checkerMu.Unlock() + requestNodeBuilder := NewNodeBuilder(r.checker, emitContext) // TODO: cache per-context + return requestNodeBuilder.SerializeTypeParametersForSignature(original, enclosingDeclaration, flags, internalFlags, tracker) +} + func (r *emitResolver) CreateTypeOfDeclaration(emitContext *printer.EmitContext, declaration *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) *ast.Node { original := emitContext.ParseNode(declaration) if original == nil { diff --git a/internal/checker/nodebuilder.go b/internal/checker/nodebuilder.go index 497a59c0e4..f3c0bf4829 100644 --- a/internal/checker/nodebuilder.go +++ b/internal/checker/nodebuilder.go @@ -90,6 +90,13 @@ func (b *NodeBuilder) SerializeReturnTypeForSignature(signatureDeclaration *ast. return b.exitContext(b.impl.serializeInferredReturnTypeForSignature(signature, returnType)) } +func (b *NodeBuilder) SerializeTypeParametersForSignature(signatureDeclaration *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) []*ast.Node { + b.enterContext(enclosingDeclaration, flags, internalFlags, tracker) + symbol := b.impl.ch.getSymbolOfDeclaration(signatureDeclaration) + typeParams := b.SymbolToTypeParameterDeclarations(symbol, enclosingDeclaration, flags, internalFlags, tracker) + return b.exitContextSlice(typeParams) +} + // SerializeTypeForDeclaration implements NodeBuilderInterface. func (b *NodeBuilder) SerializeTypeForDeclaration(declaration *ast.Node, symbol *ast.Symbol, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) *ast.Node { b.enterContext(enclosingDeclaration, flags, internalFlags, tracker) diff --git a/internal/checker/nodebuilderimpl.go b/internal/checker/nodebuilderimpl.go index c0e5458afc..4227c2fb8c 100644 --- a/internal/checker/nodebuilderimpl.go +++ b/internal/checker/nodebuilderimpl.go @@ -1526,6 +1526,12 @@ func (b *nodeBuilderImpl) typeParametersToTypeParameterDeclarations(symbol *ast. results = append(results, b.typeParameterToDeclaration(param)) } return results + } else if targetSymbol.Flags&ast.SymbolFlagsFunction != 0 { + var results []*ast.Node + for _, param := range b.ch.getTypeParametersFromDeclaration(symbol.ValueDeclaration) { + results = append(results, b.typeParameterToDeclaration(param)) + } + return results } return nil } @@ -1760,13 +1766,13 @@ func (b *nodeBuilderImpl) signatureToSignatureDeclarationHelper(signature *Signa } node = b.f.NewMethodSignatureDeclaration(modifierList, name, questionToken, typeParamList, paramList, returnTypeNode) case kind == ast.KindMethodDeclaration: - node = b.f.NewMethodDeclaration(modifierList, nil /*asteriskToken*/, name, nil /*questionToken*/, typeParamList, paramList, returnTypeNode, nil /*body*/) + node = b.f.NewMethodDeclaration(modifierList, nil /*asteriskToken*/, name, nil /*questionToken*/, typeParamList, paramList, returnTypeNode, nil /*fullSignature*/, nil /*body*/) case kind == ast.KindConstructor: - node = b.f.NewConstructorDeclaration(modifierList, nil /*typeParamList*/, paramList, nil /*returnTypeNode*/, nil /*body*/) + node = b.f.NewConstructorDeclaration(modifierList, nil /*typeParamList*/, paramList, nil /*returnTypeNode*/, nil /*fullSignature*/, nil /*body*/) case kind == ast.KindGetAccessor: - node = b.f.NewGetAccessorDeclaration(modifierList, name, nil /*typeParamList*/, paramList, returnTypeNode, nil /*body*/) + node = b.f.NewGetAccessorDeclaration(modifierList, name, nil /*typeParamList*/, paramList, returnTypeNode, nil /*fullSignature*/, nil /*body*/) case kind == ast.KindSetAccessor: - node = b.f.NewSetAccessorDeclaration(modifierList, name, nil /*typeParamList*/, paramList, nil /*returnTypeNode*/, nil /*body*/) + node = b.f.NewSetAccessorDeclaration(modifierList, name, nil /*typeParamList*/, paramList, nil /*returnTypeNode*/, nil /*fullSignature*/, nil /*body*/) case kind == ast.KindIndexSignature: node = b.f.NewIndexSignatureDeclaration(modifierList, paramList, returnTypeNode) // !!! JSDoc Support @@ -1784,12 +1790,12 @@ func (b *nodeBuilderImpl) signatureToSignatureDeclarationHelper(signature *Signa node = b.f.NewConstructorTypeNode(modifierList, typeParamList, paramList, returnTypeNode) case kind == ast.KindFunctionDeclaration: // TODO: assert name is Identifier - node = b.f.NewFunctionDeclaration(modifierList, nil /*asteriskToken*/, name, typeParamList, paramList, returnTypeNode, nil /*body*/) + node = b.f.NewFunctionDeclaration(modifierList, nil /*asteriskToken*/, name, typeParamList, paramList, returnTypeNode, nil /*fullSignature*/, nil /*body*/) case kind == ast.KindFunctionExpression: // TODO: assert name is Identifier - node = b.f.NewFunctionExpression(modifierList, nil /*asteriskToken*/, name, typeParamList, paramList, returnTypeNode, b.f.NewBlock(b.f.NewNodeList([]*ast.Node{}), false)) + node = b.f.NewFunctionExpression(modifierList, nil /*asteriskToken*/, name, typeParamList, paramList, returnTypeNode, nil /*fullSignature*/, b.f.NewBlock(b.f.NewNodeList([]*ast.Node{}), false)) case kind == ast.KindArrowFunction: - node = b.f.NewArrowFunction(modifierList, typeParamList, paramList, returnTypeNode, nil /*equalsGreaterThanToken*/, b.f.NewBlock(b.f.NewNodeList([]*ast.Node{}), false)) + node = b.f.NewArrowFunction(modifierList, typeParamList, paramList, returnTypeNode, nil /*fullSignature*/, nil /*equalsGreaterThanToken*/, b.f.NewBlock(b.f.NewNodeList([]*ast.Node{}), false)) default: panic("Unhandled kind in signatureToSignatureDeclarationHelper") } diff --git a/internal/checker/relater.go b/internal/checker/relater.go index 91d7207459..11b2909e70 100644 --- a/internal/checker/relater.go +++ b/internal/checker/relater.go @@ -1999,11 +1999,19 @@ func (c *Checker) getTypePredicateOfSignature(sig *Signature) *TypePredicate { default: if sig.declaration != nil { typeNode := sig.declaration.Type() + var jsdocTypePredicate *TypePredicate + if typeNode == nil { + if jsdocSignature := c.getSignatureOfFullSignatureType(sig.declaration); jsdocSignature != nil { + jsdocTypePredicate = c.getTypePredicateOfSignature(jsdocSignature) + } + } switch { case typeNode != nil: if ast.IsTypePredicateNode(typeNode) { sig.resolvedTypePredicate = c.createTypePredicateFromTypePredicateNode(typeNode, sig) } + case jsdocTypePredicate != nil: + sig.resolvedTypePredicate = jsdocTypePredicate case ast.IsFunctionLikeDeclaration(sig.declaration) && (sig.resolvedReturnType == nil || sig.resolvedReturnType.flags&TypeFlagsBoolean != 0) && c.getParameterCount(sig) > 0: sig.resolvedTypePredicate = c.noTypePredicate // avoid infinite loop sig.resolvedTypePredicate = c.getTypePredicateFromBody(sig.declaration) diff --git a/internal/diagnostics/diagnostics_generated.go b/internal/diagnostics/diagnostics_generated.go index e26044f260..d5f1d5b8e1 100644 --- a/internal/diagnostics/diagnostics_generated.go +++ b/internal/diagnostics/diagnostics_generated.go @@ -3466,7 +3466,7 @@ var JSDoc_may_only_appear_in_the_last_parameter_of_a_signature = &Message{code: var JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type = &Message{code: 8029, category: CategoryError, key: "JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_h_8029", text: "JSDoc '@param' tag has name '{0}', but there is no parameter with that name. It would match 'arguments' if it had an array type."} -var The_type_of_a_function_declaration_must_match_the_function_s_signature = &Message{code: 8030, category: CategoryError, key: "The_type_of_a_function_declaration_must_match_the_function_s_signature_8030", text: "The type of a function declaration must match the function's signature."} +var A_JSDoc_type_tag_on_a_function_must_have_a_signature_with_the_correct_number_of_arguments = &Message{code: 8030, category: CategoryError, key: "A_JSDoc_type_tag_on_a_function_must_have_a_signature_with_the_correct_number_of_arguments_8030", text: "A JSDoc '@type' tag on a function must have a signature with the correct number of arguments."} var You_cannot_rename_a_module_via_a_global_import = &Message{code: 8031, category: CategoryError, key: "You_cannot_rename_a_module_via_a_global_import_8031", text: "You cannot rename a module via a global import."} @@ -3486,6 +3486,8 @@ var Decorators_may_not_appear_after_export_or_export_default_if_they_also_appear var A_JSDoc_template_tag_may_not_follow_a_typedef_callback_or_overload_tag = &Message{code: 8039, category: CategoryError, key: "A_JSDoc_template_tag_may_not_follow_a_typedef_callback_or_overload_tag_8039", text: "A JSDoc '@template' tag may not follow a '@typedef', '@callback', or '@overload' tag"} +var A_JSDoc_type_tag_may_not_occur_with_a_param_or_returns_tag = &Message{code: 8040, category: CategoryError, key: "A_JSDoc_type_tag_may_not_occur_with_a_param_or_returns_tag_8040", text: "A JSDoc '@type' tag may not occur with a '@param' or '@returns' tag."} + var Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_declaration_emit = &Message{code: 9005, category: CategoryError, key: "Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_9005", text: "Declaration emit for this file requires using private name '{0}'. An explicit type annotation may unblock declaration emit."} var Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit = &Message{code: 9006, category: CategoryError, key: "Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotati_9006", text: "Declaration emit for this file requires using private name '{0}' from module '{1}'. An explicit type annotation may unblock declaration emit."} diff --git a/internal/diagnostics/extraDiagnosticMessages.json b/internal/diagnostics/extraDiagnosticMessages.json index 5c1416391a..4e64552426 100644 --- a/internal/diagnostics/extraDiagnosticMessages.json +++ b/internal/diagnostics/extraDiagnosticMessages.json @@ -14,5 +14,13 @@ "Non-relative paths are not allowed. Did you forget a leading './'?": { "category": "Error", "code": 5090 + }, + "A JSDoc '@type' tag on a function must have a signature with the correct number of arguments.": { + "category": "Error", + "code": 8030 + }, + "A JSDoc '@type' tag may not occur with a '@param' or '@returns' tag.": { + "category": "Error", + "code": 8040 } } diff --git a/internal/parser/parser.go b/internal/parser/parser.go index cd39d643ae..95c01f1504 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -1623,7 +1623,7 @@ func (p *Parser) parseFunctionDeclaration(pos int, hasJSDoc bool, modifiers *ast returnType := p.parseReturnType(ast.KindColonToken, false /*isType*/) body := p.parseFunctionBlockOrSemicolon(signatureFlags, diagnostics.X_or_expected) p.contextFlags = saveContextFlags - result := p.factory.NewFunctionDeclaration(modifiers, asteriskToken, name, typeParameters, parameters, returnType, body) + result := p.factory.NewFunctionDeclaration(modifiers, asteriskToken, name, typeParameters, parameters, returnType, nil /*fullSignature*/, body) p.finishNode(result, pos) p.withJSDoc(result, hasJSDoc) return result @@ -1812,7 +1812,7 @@ func (p *Parser) tryParseConstructorDeclaration(pos int, hasJSDoc bool, modifier parameters := p.parseParameters(ParseFlagsNone) returnType := p.parseReturnType(ast.KindColonToken, false /*isType*/) body := p.parseFunctionBlockOrSemicolon(ParseFlagsNone, diagnostics.X_or_expected) - result := p.factory.NewConstructorDeclaration(modifiers, typeParameters, parameters, returnType, body) + result := p.factory.NewConstructorDeclaration(modifiers, typeParameters, parameters, returnType, nil /*fullSignature*/, body) p.finishNode(result, pos) p.withJSDoc(result, hasJSDoc) return result @@ -1843,7 +1843,7 @@ func (p *Parser) parseMethodDeclaration(pos int, hasJSDoc bool, modifiers *ast.M parameters := p.parseParameters(signatureFlags) typeNode := p.parseReturnType(ast.KindColonToken, false /*isType*/) body := p.parseFunctionBlockOrSemicolon(signatureFlags, diagnosticMessage) - result := p.factory.NewMethodDeclaration(modifiers, asteriskToken, name, questionToken, typeParameters, parameters, typeNode, body) + result := p.factory.NewMethodDeclaration(modifiers, asteriskToken, name, questionToken, typeParameters, parameters, typeNode, nil /*fullSignature*/, body) p.finishNode(result, pos) p.withJSDoc(result, hasJSDoc) return result @@ -3363,9 +3363,9 @@ func (p *Parser) parseAccessorDeclaration(pos int, hasJSDoc bool, modifiers *ast var result *ast.Node // Keep track of `typeParameters` (for both) and `type` (for setters) if they were parsed those indicate grammar errors if kind == ast.KindGetAccessor { - result = p.factory.NewGetAccessorDeclaration(modifiers, name, typeParameters, parameters, returnType, body) + result = p.factory.NewGetAccessorDeclaration(modifiers, name, typeParameters, parameters, returnType, nil /*fullSignature*/, body) } else { - result = p.factory.NewSetAccessorDeclaration(modifiers, name, typeParameters, parameters, returnType, body) + result = p.factory.NewSetAccessorDeclaration(modifiers, name, typeParameters, parameters, returnType, nil /*fullSignature*/, body) } p.finishNode(result, pos) p.withJSDoc(result, hasJSDoc) @@ -4385,7 +4385,7 @@ func (p *Parser) parseParenthesizedArrowFunctionExpression(allowAmbiguity bool, return nil } } - result := p.factory.NewArrowFunction(modifiers, typeParameters, parameters, returnType, equalsGreaterThanToken, body) + result := p.factory.NewArrowFunction(modifiers, typeParameters, parameters, returnType, nil /*fullSignature*/, equalsGreaterThanToken, body) p.finishNode(result, pos) p.withJSDoc(result, hasJSDoc) return result @@ -4499,7 +4499,7 @@ func (p *Parser) parseSimpleArrowFunctionExpression(pos int, identifier *ast.Nod parameters := p.newNodeList(parameter.Loc, []*ast.Node{parameter}) equalsGreaterThanToken := p.parseExpectedToken(ast.KindEqualsGreaterThanToken) body := p.parseArrowFunctionExpressionBody(asyncModifier != nil /*isAsync*/, allowReturnTypeInArrowFunction) - result := p.factory.NewArrowFunction(asyncModifier, nil /*typeParameters*/, parameters, nil /*returnType*/, equalsGreaterThanToken, body) + result := p.factory.NewArrowFunction(asyncModifier, nil /*typeParameters*/, parameters, nil /*returnType*/, nil /*fullSignature*/, equalsGreaterThanToken, body) p.finishNode(result, pos) p.withJSDoc(result, hasJSDoc) return result @@ -5723,7 +5723,7 @@ func (p *Parser) parseFunctionExpression() *ast.Expression { returnType := p.parseReturnType(ast.KindColonToken, false /*isType*/) body := p.parseFunctionBlock(signatureFlags, nil /*diagnosticMessage*/) p.contextFlags = saveContexFlags - result := p.factory.NewFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, returnType, body) + result := p.factory.NewFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, returnType, nil /*fullSignature*/, body) p.finishNode(result, pos) p.withJSDoc(result, hasJSDoc) return result diff --git a/internal/parser/reparser.go b/internal/parser/reparser.go index d36b244493..5b82837c3c 100644 --- a/internal/parser/reparser.go +++ b/internal/parser/reparser.go @@ -137,11 +137,11 @@ func (p *Parser) reparseJSDocSignature(jsSignature *ast.Node, fun *ast.Node, jsD clonedModifiers := p.factory.DeepCloneReparseModifiers(modifiers) switch fun.Kind { case ast.KindFunctionDeclaration, ast.KindFunctionExpression, ast.KindArrowFunction: - signature = p.factory.NewFunctionDeclaration(clonedModifiers, nil, p.factory.DeepCloneReparse(fun.Name()), nil, nil, nil, nil) + signature = p.factory.NewFunctionDeclaration(clonedModifiers, nil, p.factory.DeepCloneReparse(fun.Name()), nil, nil, nil, nil, nil) case ast.KindMethodDeclaration, ast.KindMethodSignature: - signature = p.factory.NewMethodDeclaration(clonedModifiers, nil, p.factory.DeepCloneReparse(fun.Name()), nil, nil, nil, nil, nil) + signature = p.factory.NewMethodDeclaration(clonedModifiers, nil, p.factory.DeepCloneReparse(fun.Name()), nil, nil, nil, nil, nil, nil) case ast.KindConstructor: - signature = p.factory.NewConstructorDeclaration(clonedModifiers, nil, nil, nil, nil) + signature = p.factory.NewConstructorDeclaration(clonedModifiers, nil, nil, nil, nil, nil) case ast.KindJSDocCallbackTag: signature = p.factory.NewFunctionTypeNode(nil, nil, nil) default: @@ -297,7 +297,7 @@ func (p *Parser) reparseHosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Node) if declaration.Type() == nil && tag.AsJSDocTypeTag().TypeExpression != nil { declaration.AsMutable().SetType(p.factory.DeepCloneReparse(tag.AsJSDocTypeTag().TypeExpression.Type())) p.finishMutatedNode(declaration) - break + return } } } @@ -307,11 +307,13 @@ func (p *Parser) reparseHosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Node) if parent.Type() == nil && tag.AsJSDocTypeTag().TypeExpression != nil { parent.AsMutable().SetType(p.factory.DeepCloneReparse(tag.AsJSDocTypeTag().TypeExpression.Type())) p.finishMutatedNode(parent) + return } case ast.KindParameter: if parent.Type() == nil && tag.AsJSDocTypeTag().TypeExpression != nil { parent.AsMutable().SetType(p.reparseJSDocTypeLiteral(tag.AsJSDocTypeTag().TypeExpression.Type())) p.finishMutatedNode(parent) + return } case ast.KindExpressionStatement: if parent.AsExpressionStatement().Expression.Kind == ast.KindBinaryExpression { @@ -319,6 +321,7 @@ func (p *Parser) reparseHosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Node) if kind := ast.GetAssignmentDeclarationKind(bin); kind != ast.JSDeclarationKindNone && tag.AsJSDocTypeTag().TypeExpression != nil { bin.AsMutable().SetType(p.factory.DeepCloneReparse(tag.AsJSDocTypeTag().TypeExpression.Type())) p.finishMutatedNode(bin.AsNode()) + return } } case ast.KindReturnStatement, ast.KindParenthesizedExpression: @@ -328,6 +331,14 @@ func (p *Parser) reparseHosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Node) p.factory.DeepCloneReparse(parent.Expression()), true /*isAssertion*/)) p.finishMutatedNode(parent) + return + } + } + if fun, ok := getFunctionLikeHost(parent); ok { + noTypedParams := core.Every(fun.Parameters(), func(param *ast.Node) bool { return param.Type() == nil }) + if fun.Type() == nil && noTypedParams && tag.AsJSDocTypeTag().TypeExpression != nil { + fun.FunctionLikeData().FullSignature = p.factory.DeepCloneReparse(tag.AsJSDocTypeTag().TypeExpression.Type()) + p.finishMutatedNode(fun) } } case ast.KindJSDocSatisfiesTag: diff --git a/internal/printer/emitresolver.go b/internal/printer/emitresolver.go index f8a1f6c842..b973bdca41 100644 --- a/internal/printer/emitresolver.go +++ b/internal/printer/emitresolver.go @@ -57,6 +57,7 @@ type EmitResolver interface { // Node construction for declaration emit CreateTypeOfDeclaration(emitContext *EmitContext, declaration *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) *ast.Node CreateReturnTypeOfSignatureDeclaration(emitContext *EmitContext, signatureDeclaration *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) *ast.Node + CreateTypeParametersOfSignatureDeclaration(emitContext *EmitContext, signatureDeclaration *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) []*ast.Node CreateLiteralConstValue(emitContext *EmitContext, node *ast.Node, tracker nodebuilder.SymbolTracker) *ast.Node CreateTypeOfExpression(emitContext *EmitContext, expression *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) *ast.Node CreateLateBoundIndexSignatures(emitContext *EmitContext, container *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) []*ast.Node diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index da14de4ea3..239928fad0 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -1141,6 +1141,7 @@ func TestParenthesizeArrowFunction1(t *testing.T) { nil, /*typeParameters*/ factory.NewNodeList([]*ast.Node{}), nil, /*returnType*/ + nil, /*fullSignature*/ factory.NewToken(ast.KindEqualsGreaterThanToken), // will be parenthesized on emit: factory.NewObjectLiteralExpression( @@ -1168,6 +1169,7 @@ func TestParenthesizeArrowFunction2(t *testing.T) { nil, /*typeParameters*/ factory.NewNodeList([]*ast.Node{}), nil, /*returnType*/ + nil, /*fullSignature*/ factory.NewToken(ast.KindEqualsGreaterThanToken), // will be parenthesized on emit: factory.NewPropertyAccessExpression( @@ -1347,6 +1349,7 @@ func makeSide(label string, kind ast.Kind, factory *ast.NodeFactory) *ast.Node { nil, /*typeParameters*/ factory.NewNodeList([]*ast.Node{}), nil, /*returnType*/ + nil, /*fullSignature*/ factory.NewToken(ast.KindEqualsGreaterThanToken), factory.NewBlock(factory.NewNodeList([]*ast.Node{}), false /*multiLine*/), ) @@ -1485,6 +1488,7 @@ func TestParenthesizeConditional3(t *testing.T) { nil, /*typeParameters*/ factory.NewNodeList([]*ast.Node{}), nil, /*returnType*/ + nil, /*fullSignature*/ factory.NewToken(ast.KindEqualsGreaterThanToken), factory.NewBlock( factory.NewNodeList([]*ast.Node{}), @@ -1869,6 +1873,7 @@ func TestParenthesizeExpressionStatement2(t *testing.T) { []*ast.Node{}, ), nil, /*returnType*/ + nil, /*fullSignature*/ factory.NewBlock( factory.NewNodeList([]*ast.Node{}), false, /*multiLine*/ @@ -1954,6 +1959,7 @@ func TestParenthesizeExpressionDefault2(t *testing.T) { []*ast.Node{}, ), nil, /*returnType*/ + nil, /*fullSignature*/ factory.NewBlock( factory.NewNodeList( []*ast.Node{}, @@ -2435,6 +2441,7 @@ func TestNameGeneration(t *testing.T) { nil, ec.Factory.NewNodeList([]*ast.Node{}), nil, + nil, ec.Factory.NewBlock(ec.Factory.NewNodeList([]*ast.Node{ ec.Factory.NewVariableStatement(nil, ec.Factory.NewVariableDeclarationList( ast.NodeFlagsNone, diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 52b09dedcb..ad80436fb1 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -753,6 +753,7 @@ func (tx *DeclarationTransformer) transformSetAccessorDeclaration(input *ast.Set tx.updateAccessorParamList(input.AsNode(), tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsPrivate) != 0), nil, nil, + nil, ) } @@ -768,6 +769,7 @@ func (tx *DeclarationTransformer) transformGetAccesorDeclaration(input *ast.GetA tx.updateAccessorParamList(input.AsNode(), tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsPrivate) != 0), tx.ensureType(input.AsNode(), false), nil, + nil, ) } @@ -819,6 +821,7 @@ func (tx *DeclarationTransformer) transformConstructorDeclaration(input *ast.Con tx.updateParamList(input.AsNode(), input.Parameters), nil, // no return type nil, + nil, ) } @@ -879,6 +882,7 @@ func (tx *DeclarationTransformer) transformMethodDeclaration(input *ast.MethodDe tx.updateParamList(input.AsNode(), input.Parameters), tx.ensureType(input.AsNode(), false), nil, + nil, ) } } @@ -1141,6 +1145,7 @@ func (tx *DeclarationTransformer) transformFunctionDeclaration(input *ast.Functi tx.ensureTypeParams(input.AsNode(), input.TypeParameters), tx.updateParamList(input.AsNode(), input.Parameters), tx.ensureType(input.AsNode(), false), + nil, /*fullSignature*/ nil, ) if updated == nil || !tx.resolver.IsExpandoFunctionDeclaration(input.AsNode()) || !shouldEmitFunctionProperties(input) { @@ -1501,7 +1506,36 @@ func (tx *DeclarationTransformer) ensureTypeParams(node *ast.Node, params *ast.T if tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(node), ast.ModifierFlagsPrivate) != 0 { return nil } - return tx.Visitor().VisitNodes(params) + var typeParameters *ast.TypeParameterList + if typeParameters = tx.Visitor().VisitNodes(params); typeParameters != nil { + return typeParameters + } + oldErrorNameNode := tx.state.errorNameNode + tx.state.errorNameNode = node.Name() + var oldDiag GetSymbolAccessibilityDiagnostic + if !tx.suppressNewDiagnosticContexts { + oldDiag = tx.state.getSymbolAccessibilityDiagnostic + if canProduceDiagnostics(node) { + tx.state.getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node) + } + } + + if data := node.FunctionLikeData(); data != nil && data.FullSignature != nil { + if nodes := tx.resolver.CreateTypeParametersOfSignatureDeclaration(tx.EmitContext(), node, tx.enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, tx.tracker); nodes != nil { + typeParameters = &ast.TypeParameterList{ + Loc: node.Loc, + Nodes: nodes, + } + } + } else { + // Debug.assertNever(node); // !!! + } + + tx.state.errorNameNode = oldErrorNameNode + if !tx.suppressNewDiagnosticContexts { + tx.state.getSymbolAccessibilityDiagnostic = oldDiag + } + return typeParameters } func (tx *DeclarationTransformer) updateParamList(node *ast.Node, params *ast.ParameterList) *ast.ParameterList { diff --git a/internal/transformers/moduletransforms/commonjsmodule.go b/internal/transformers/moduletransforms/commonjsmodule.go index 434e89d6cf..e1f1c9ac2a 100644 --- a/internal/transformers/moduletransforms/commonjsmodule.go +++ b/internal/transformers/moduletransforms/commonjsmodule.go @@ -626,6 +626,7 @@ func (tx *CommonJSModuleTransformer) createExportExpression(name *ast.ModuleExpo nil, /*typeParameters*/ tx.Factory().NewNodeList([]*ast.Node{}), nil, /*type*/ + nil, /*fullSignature*/ tx.Factory().NewBlock( tx.Factory().NewNodeList([]*ast.Node{ tx.Factory().NewReturnStatement(value), @@ -946,6 +947,7 @@ func (tx *CommonJSModuleTransformer) visitTopLevelFunctionDeclaration(node *ast. nil, /*typeParameters*/ tx.Visitor().VisitNodes(node.Parameters), nil, /*type*/ + nil, /*fullSignature*/ tx.Visitor().VisitNode(node.Body), ) } else { @@ -1512,6 +1514,7 @@ func (tx *CommonJSModuleTransformer) visitDestructuringAssignmentTargetNoStack(n nil, /*typeParameters*/ tx.Factory().NewNodeList([]*ast.Node{param}), nil, /*returnType*/ + nil, /*fullSignature*/ tx.Factory().NewBlock(statementList, false /*multiLine*/), ) propertyList := tx.Factory().NewNodeList([]*ast.Node{valueSetter}) @@ -1785,6 +1788,7 @@ func (tx *CommonJSModuleTransformer) createImportCallExpressionCommonJS(arg *ast nil, /*typeParameters*/ tx.Factory().NewNodeList(parameters), nil, /*type*/ + nil, /*fullSignature*/ tx.Factory().NewToken(ast.KindEqualsGreaterThanToken), /*equalsGreaterThanToken*/ requireCall, ) diff --git a/internal/transformers/tstransforms/runtimesyntax.go b/internal/transformers/tstransforms/runtimesyntax.go index 4c994085fd..7dde1d81d2 100644 --- a/internal/transformers/tstransforms/runtimesyntax.go +++ b/internal/transformers/tstransforms/runtimesyntax.go @@ -344,7 +344,7 @@ func (tx *RuntimeSyntaxTransformer) visitEnumDeclaration(node *ast.EnumDeclarati enumParam := tx.Factory().NewParameterDeclaration(nil, nil, enumParamName, nil, nil, nil) enumBody := tx.transformEnumBody(node) - enumFunc := tx.Factory().NewFunctionExpression(nil, nil, nil, nil, tx.Factory().NewNodeList([]*ast.Node{enumParam}), nil, enumBody) + enumFunc := tx.Factory().NewFunctionExpression(nil, nil, nil, nil, tx.Factory().NewNodeList([]*ast.Node{enumParam}), nil, nil, enumBody) enumCall := tx.Factory().NewCallExpression(tx.Factory().NewParenthesizedExpression(enumFunc), nil, nil, tx.Factory().NewNodeList([]*ast.Node{enumArg}), ast.NodeFlagsNone) enumStatement := tx.Factory().NewExpressionStatement(enumCall) tx.EmitContext().SetOriginal(enumStatement, node.AsNode()) @@ -588,7 +588,7 @@ func (tx *RuntimeSyntaxTransformer) visitModuleDeclaration(node *ast.ModuleDecla moduleParam := tx.Factory().NewParameterDeclaration(nil, nil, moduleParamName, nil, nil, nil) moduleBody := tx.transformModuleBody(node, tx.getNamespaceContainerName(node.AsNode())) - moduleFunc := tx.Factory().NewFunctionExpression(nil, nil, nil, nil, tx.Factory().NewNodeList([]*ast.Node{moduleParam}), nil, moduleBody) + moduleFunc := tx.Factory().NewFunctionExpression(nil, nil, nil, nil, tx.Factory().NewNodeList([]*ast.Node{moduleParam}), nil, nil, moduleBody) moduleCall := tx.Factory().NewCallExpression(tx.Factory().NewParenthesizedExpression(moduleFunc), nil, nil, tx.Factory().NewNodeList([]*ast.Node{moduleArg}), ast.NodeFlagsNone) moduleStatement := tx.Factory().NewExpressionStatement(moduleCall) tx.EmitContext().SetOriginal(moduleStatement, node.AsNode()) @@ -724,6 +724,7 @@ func (tx *RuntimeSyntaxTransformer) visitFunctionDeclaration(node *ast.FunctionD nil, /*typeParameters*/ tx.Visitor().VisitNodes(node.Parameters), nil, /*returnType*/ + nil, /*fullSignature*/ tx.Visitor().VisitNode(node.Body), ) export := tx.createExportStatementForDeclaration(node.AsNode()) @@ -829,7 +830,7 @@ func (tx *RuntimeSyntaxTransformer) visitConstructorDeclaration(node *ast.Constr modifiers := tx.Visitor().VisitModifiers(node.Modifiers()) parameters := tx.EmitContext().VisitParameters(node.ParameterList(), tx.Visitor()) body := tx.visitConstructorBody(node.Body.AsBlock(), node.AsNode()) - return tx.Factory().UpdateConstructorDeclaration(node, modifiers, nil /*typeParameters*/, parameters, nil /*returnType*/, body) + return tx.Factory().UpdateConstructorDeclaration(node, modifiers, nil /*typeParameters*/, parameters, nil /*returnType*/, nil /*fullSignature*/, body) } func (tx *RuntimeSyntaxTransformer) visitConstructorBody(body *ast.Block, constructor *ast.Node) *ast.Node { diff --git a/internal/transformers/tstransforms/typeeraser.go b/internal/transformers/tstransforms/typeeraser.go index 1d0d96c83e..6e78e69667 100644 --- a/internal/transformers/tstransforms/typeeraser.go +++ b/internal/transformers/tstransforms/typeeraser.go @@ -136,7 +136,7 @@ func (tx *TypeEraserTransformer) visit(node *ast.Node) *ast.Node { // TypeScript overloads are elided return nil } - return tx.Factory().UpdateConstructorDeclaration(n, nil, nil, tx.Visitor().VisitNodes(n.Parameters), nil, tx.Visitor().VisitNode(n.Body)) + return tx.Factory().UpdateConstructorDeclaration(n, nil, nil, tx.Visitor().VisitNodes(n.Parameters), nil, nil, tx.Visitor().VisitNode(n.Body)) case ast.KindMethodDeclaration: n := node.AsMethodDeclaration() @@ -144,7 +144,7 @@ func (tx *TypeEraserTransformer) visit(node *ast.Node) *ast.Node { // TypeScript overloads are elided return nil } - return tx.Factory().UpdateMethodDeclaration(n, tx.Visitor().VisitModifiers(n.Modifiers()), n.AsteriskToken, tx.Visitor().VisitNode(n.Name()), nil, nil, tx.Visitor().VisitNodes(n.Parameters), nil, tx.Visitor().VisitNode(n.Body)) + return tx.Factory().UpdateMethodDeclaration(n, tx.Visitor().VisitModifiers(n.Modifiers()), n.AsteriskToken, tx.Visitor().VisitNode(n.Name()), nil, nil, tx.Visitor().VisitNodes(n.Parameters), nil, nil, tx.Visitor().VisitNode(n.Body)) case ast.KindGetAccessor: n := node.AsGetAccessorDeclaration() @@ -152,7 +152,7 @@ func (tx *TypeEraserTransformer) visit(node *ast.Node) *ast.Node { // TypeScript overloads are elided return nil } - return tx.Factory().UpdateGetAccessorDeclaration(n, tx.Visitor().VisitModifiers(n.Modifiers()), tx.Visitor().VisitNode(n.Name()), nil, tx.Visitor().VisitNodes(n.Parameters), nil, tx.Visitor().VisitNode(n.Body)) + return tx.Factory().UpdateGetAccessorDeclaration(n, tx.Visitor().VisitModifiers(n.Modifiers()), tx.Visitor().VisitNode(n.Name()), nil, tx.Visitor().VisitNodes(n.Parameters), nil, nil, tx.Visitor().VisitNode(n.Body)) case ast.KindSetAccessor: n := node.AsSetAccessorDeclaration() @@ -160,7 +160,7 @@ func (tx *TypeEraserTransformer) visit(node *ast.Node) *ast.Node { // TypeScript overloads are elided return nil } - return tx.Factory().UpdateSetAccessorDeclaration(n, tx.Visitor().VisitModifiers(n.Modifiers()), tx.Visitor().VisitNode(n.Name()), nil, tx.Visitor().VisitNodes(n.Parameters), nil, tx.Visitor().VisitNode(n.Body)) + return tx.Factory().UpdateSetAccessorDeclaration(n, tx.Visitor().VisitModifiers(n.Modifiers()), tx.Visitor().VisitNode(n.Name()), nil, tx.Visitor().VisitNodes(n.Parameters), nil, nil, tx.Visitor().VisitNode(n.Body)) case ast.KindVariableDeclaration: n := node.AsVariableDeclaration() @@ -188,15 +188,15 @@ func (tx *TypeEraserTransformer) visit(node *ast.Node) *ast.Node { // TypeScript overloads are elided return tx.elide(node) } - return tx.Factory().UpdateFunctionDeclaration(n, tx.Visitor().VisitModifiers(n.Modifiers()), n.AsteriskToken, tx.Visitor().VisitNode(n.Name()), nil, tx.Visitor().VisitNodes(n.Parameters), nil, tx.Visitor().VisitNode(n.Body)) + return tx.Factory().UpdateFunctionDeclaration(n, tx.Visitor().VisitModifiers(n.Modifiers()), n.AsteriskToken, tx.Visitor().VisitNode(n.Name()), nil, tx.Visitor().VisitNodes(n.Parameters), nil, nil, tx.Visitor().VisitNode(n.Body)) case ast.KindFunctionExpression: n := node.AsFunctionExpression() - return tx.Factory().UpdateFunctionExpression(n, tx.Visitor().VisitModifiers(n.Modifiers()), n.AsteriskToken, tx.Visitor().VisitNode(n.Name()), nil, tx.Visitor().VisitNodes(n.Parameters), nil, tx.Visitor().VisitNode(n.Body)) + return tx.Factory().UpdateFunctionExpression(n, tx.Visitor().VisitModifiers(n.Modifiers()), n.AsteriskToken, tx.Visitor().VisitNode(n.Name()), nil, tx.Visitor().VisitNodes(n.Parameters), nil, nil, tx.Visitor().VisitNode(n.Body)) case ast.KindArrowFunction: n := node.AsArrowFunction() - return tx.Factory().UpdateArrowFunction(n, tx.Visitor().VisitModifiers(n.Modifiers()), nil, tx.Visitor().VisitNodes(n.Parameters), nil, n.EqualsGreaterThanToken, tx.Visitor().VisitNode(n.Body)) + return tx.Factory().UpdateArrowFunction(n, tx.Visitor().VisitModifiers(n.Modifiers()), nil, tx.Visitor().VisitNodes(n.Parameters), nil, nil, n.EqualsGreaterThanToken, tx.Visitor().VisitNode(n.Body)) case ast.KindParameter: if ast.IsThisParameter(node) { diff --git a/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.errors.txt b/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.errors.txt new file mode 100644 index 0000000000..45259ff67b --- /dev/null +++ b/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.errors.txt @@ -0,0 +1,33 @@ +/a.js(2,11): error TS8040: A JSDoc '@type' tag may not occur with a '@param' or '@returns' tag. +/a.js(8,11): error TS8040: A JSDoc '@type' tag may not occur with a '@param' or '@returns' tag. +/a.js(15,11): error TS8040: A JSDoc '@type' tag may not occur with a '@param' or '@returns' tag. + + +==== /a.js (3 errors) ==== + /** + * @type {(a: 1) => true} + ~~~~~~~~~~~~~~ +!!! error TS8040: A JSDoc '@type' tag may not occur with a '@param' or '@returns' tag. + * @param {2} a + */ + export function conflictingParam(a) { return true } + + /** + * @type {(b: 3) => true} + ~~~~~~~~~~~~~~ +!!! error TS8040: A JSDoc '@type' tag may not occur with a '@param' or '@returns' tag. + * @return {false} + */ + export function conflictingReturn(b) { return false } + + + /** + * @type {(c: 4) => true} + ~~~~~~~~~~~~~~ +!!! error TS8040: A JSDoc '@type' tag may not occur with a '@param' or '@returns' tag. + * @param {5} d + * @return {false} + */ + export function conflictingBoth(d) { return false } + + \ No newline at end of file diff --git a/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.js b/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.js new file mode 100644 index 0000000000..488da6a2de --- /dev/null +++ b/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.js @@ -0,0 +1,44 @@ +//// [tests/cases/conformance/jsdoc/jsdocTypeParameterTagConflict.ts] //// + +//// [a.js] +/** + * @type {(a: 1) => true} + * @param {2} a + */ +export function conflictingParam(a) { return true } + +/** + * @type {(b: 3) => true} + * @return {false} + */ +export function conflictingReturn(b) { return false } + + +/** + * @type {(c: 4) => true} + * @param {5} d + * @return {false} + */ +export function conflictingBoth(d) { return false } + + + + + +//// [a.d.ts] +/** + * @type {(a: 1) => true} + * @param {2} a + */ +export declare function conflictingParam(a: 2): true; +/** + * @type {(b: 3) => true} + * @return {false} + */ +export declare function conflictingReturn(b: 3): false; +/** + * @type {(c: 4) => true} + * @param {5} d + * @return {false} + */ +export declare function conflictingBoth(d: 5): false; diff --git a/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.symbols b/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.symbols new file mode 100644 index 0000000000..488ac65579 --- /dev/null +++ b/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.symbols @@ -0,0 +1,30 @@ +//// [tests/cases/conformance/jsdoc/jsdocTypeParameterTagConflict.ts] //// + +=== /a.js === +/** + * @type {(a: 1) => true} + * @param {2} a + */ +export function conflictingParam(a) { return true } +>conflictingParam : Symbol(conflictingParam, Decl(a.js, 0, 0)) +>a : Symbol(a, Decl(a.js, 4, 33)) + +/** + * @type {(b: 3) => true} + * @return {false} + */ +export function conflictingReturn(b) { return false } +>conflictingReturn : Symbol(conflictingReturn, Decl(a.js, 4, 51)) +>b : Symbol(b, Decl(a.js, 10, 34)) + + +/** + * @type {(c: 4) => true} + * @param {5} d + * @return {false} + */ +export function conflictingBoth(d) { return false } +>conflictingBoth : Symbol(conflictingBoth, Decl(a.js, 10, 53)) +>d : Symbol(d, Decl(a.js, 18, 32)) + + diff --git a/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.types b/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.types new file mode 100644 index 0000000000..c011a7682c --- /dev/null +++ b/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.types @@ -0,0 +1,33 @@ +//// [tests/cases/conformance/jsdoc/jsdocTypeParameterTagConflict.ts] //// + +=== /a.js === +/** + * @type {(a: 1) => true} + * @param {2} a + */ +export function conflictingParam(a) { return true } +>conflictingParam : (a: 2) => true +>a : 2 +>true : true + +/** + * @type {(b: 3) => true} + * @return {false} + */ +export function conflictingReturn(b) { return false } +>conflictingReturn : (b: 3) => false +>b : 3 +>false : false + + +/** + * @type {(c: 4) => true} + * @param {5} d + * @return {false} + */ +export function conflictingBoth(d) { return false } +>conflictingBoth : (d: 5) => false +>d : 5 +>false : false + + diff --git a/testdata/baselines/reference/submodule/compiler/jsdocBracelessTypeTag1.errors.txt b/testdata/baselines/reference/submodule/compiler/jsdocBracelessTypeTag1.errors.txt index d8a5fdf957..5a5cdfddd4 100644 --- a/testdata/baselines/reference/submodule/compiler/jsdocBracelessTypeTag1.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/jsdocBracelessTypeTag1.errors.txt @@ -1,4 +1,4 @@ -index.js(12,14): error TS7006: Parameter 'arg' implicitly has an 'any' type. +index.js(3,3): error TS2322: Type 'number' is not assignable to type 'string'. index.js(20,16): error TS2322: Type '"other"' is not assignable to type '"bar" | "foo"'. @@ -6,6 +6,8 @@ index.js(20,16): error TS2322: Type '"other"' is not assignable to type '"bar" | /** @type () => string */ function fn1() { return 42; + ~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. } /** @type () => string */ @@ -15,8 +17,6 @@ index.js(20,16): error TS2322: Type '"other"' is not assignable to type '"bar" | /** @type (arg: string) => string */ function fn3(arg) { - ~~~ -!!! error TS7006: Parameter 'arg' implicitly has an 'any' type. return arg; } diff --git a/testdata/baselines/reference/submodule/compiler/jsdocBracelessTypeTag1.types b/testdata/baselines/reference/submodule/compiler/jsdocBracelessTypeTag1.types index 7b33e57538..670d5bd933 100644 --- a/testdata/baselines/reference/submodule/compiler/jsdocBracelessTypeTag1.types +++ b/testdata/baselines/reference/submodule/compiler/jsdocBracelessTypeTag1.types @@ -3,7 +3,7 @@ === index.js === /** @type () => string */ function fn1() { ->fn1 : () => number +>fn1 : () => string return 42; >42 : 42 @@ -19,11 +19,11 @@ function fn2() { /** @type (arg: string) => string */ function fn3(arg) { ->fn3 : (arg: any) => any ->arg : any +>fn3 : (arg: string) => string +>arg : string return arg; ->arg : any +>arg : string } /** @type ({ type: 'foo' } | { type: 'bar' }) & { prop: number } */ diff --git a/testdata/baselines/reference/submodule/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.errors.txt b/testdata/baselines/reference/submodule/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.errors.txt index fd2276e9f7..3d859304e6 100644 --- a/testdata/baselines/reference/submodule/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.errors.txt @@ -1,4 +1,3 @@ -typescript-eslint.js(12,17): error TS7019: Rest parameter 'configs' implicitly has an 'any[]' type. typescript-eslint.js(14,1): error TS2309: An export assignment cannot be used in a module with other exported elements. @@ -26,7 +25,7 @@ typescript-eslint.js(14,1): error TS2309: An export assignment cannot be used in }, }; -==== typescript-eslint.js (2 errors) ==== +==== typescript-eslint.js (1 errors) ==== /** * @typedef {{ rules: Record }} Plugin */ @@ -39,8 +38,6 @@ typescript-eslint.js(14,1): error TS2309: An export assignment cannot be used in * @type {(...configs: Config[]) => void} */ function config(...configs) { } - ~~~~~~~~~~ -!!! error TS7019: Rest parameter 'configs' implicitly has an 'any[]' type. module.exports = { config }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/testdata/baselines/reference/submodule/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.types b/testdata/baselines/reference/submodule/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.types index b805edc844..78210a6042 100644 --- a/testdata/baselines/reference/submodule/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.types +++ b/testdata/baselines/reference/submodule/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.types @@ -8,16 +8,16 @@ const eslintReact = require('./eslint-plugin-react.js'); >'./eslint-plugin-react.js' : "./eslint-plugin-react.js" const tseslint = require('./typescript-eslint.js'); ->tseslint : { config: (...configs: any[]) => void; } ->require('./typescript-eslint.js') : { config: (...configs: any[]) => void; } +>tseslint : { config: (...configs: import("./typescript-eslint.js").Config[]) => void; } +>require('./typescript-eslint.js') : { config: (...configs: import("./typescript-eslint.js").Config[]) => void; } >require : any >'./typescript-eslint.js' : "./typescript-eslint.js" tseslint.config(eslintReact) >tseslint.config(eslintReact) : void ->tseslint.config : (...configs: any[]) => void ->tseslint : { config: (...configs: any[]) => void; } ->config : (...configs: any[]) => void +>tseslint.config : (...configs: import("./typescript-eslint.js").Config[]) => void +>tseslint : { config: (...configs: import("./typescript-eslint.js").Config[]) => void; } +>config : (...configs: import("./typescript-eslint.js").Config[]) => void >eslintReact : { plugins: { react: { deprecatedRules: { "jsx-sort-default-props": boolean; }; rules: { "no-unsafe": boolean; }; }; }; } === eslint-plugin-react.js === @@ -78,14 +78,14 @@ module.exports = { * @type {(...configs: Config[]) => void} */ function config(...configs) { } ->config : (...configs: any[]) => void ->configs : any[] +>config : (...configs: Config[]) => void +>configs : Config[] module.exports = { config }; ->module.exports = { config } : { config: (...configs: any[]) => void; } ->module.exports : { config: (...configs: any[]) => void; } ->module : { "export=": { config: (...configs: any[]) => void; }; } ->exports : { config: (...configs: any[]) => void; } ->{ config } : { config: (...configs: any[]) => void; } ->config : (...configs: any[]) => void +>module.exports = { config } : { config: (...configs: Config[]) => void; } +>module.exports : { config: (...configs: Config[]) => void; } +>module : { "export=": { config: (...configs: Config[]) => void; }; } +>exports : { config: (...configs: Config[]) => void; } +>{ config } : { config: (...configs: Config[]) => void; } +>config : (...configs: Config[]) => void diff --git a/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.symbols b/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.symbols index 5f8301528a..4040a51fca 100644 --- a/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.symbols +++ b/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.symbols @@ -79,7 +79,9 @@ function f1(x) { >x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 30, 12)) x.length; +>x.length : Symbol(length, Decl(lib.es5.d.ts, --, --)) >x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 30, 12)) +>length : Symbol(length, Decl(lib.es5.d.ts, --, --)) } if (!!true) { fail(); diff --git a/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.symbols.diff b/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.symbols.diff index a95a4f34f4..4d0332fa82 100644 --- a/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.symbols.diff +++ b/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.symbols.diff @@ -29,8 +29,10 @@ x.length; ->x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) ++>x.length : Symbol(length, Decl(lib.es5.d.ts, --, --)) >x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 30, 12)) ->length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) ++>length : Symbol(length, Decl(lib.es5.d.ts, --, --)) } if (!!true) { fail(); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.types b/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.types index 7959286888..f41456723b 100644 --- a/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.types +++ b/testdata/baselines/reference/submodule/conformance/assertionsAndNonReturningFunctions.types @@ -18,15 +18,15 @@ const assert = check => { /** @type {(x: unknown) => asserts x is string } */ function assertIsString(x) { ->assertIsString : (x: any) => void ->x : any +>assertIsString : (x: unknown) => asserts x is string +>x : unknown if (!(typeof x === "string")) throw new Error(); >!(typeof x === "string") : boolean >(typeof x === "string") : boolean >typeof x === "string" : boolean >typeof x : "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined" ->x : any +>x : unknown >"string" : "string" >new Error() : Error >Error : ErrorConstructor @@ -108,13 +108,13 @@ function f1(x) { assertIsString(x); >assertIsString(x) : void ->assertIsString : (x: any) => void +>assertIsString : (x: unknown) => asserts x is string >x : any x.length; ->x.length : any ->x : any ->length : any +>x.length : number +>x : string +>length : number } if (!!true) { >!!true : boolean diff --git a/testdata/baselines/reference/submodule/conformance/callbackTagNamespace.errors.txt b/testdata/baselines/reference/submodule/conformance/callbackTagNamespace.errors.txt new file mode 100644 index 0000000000..002590dfbb --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/callbackTagNamespace.errors.txt @@ -0,0 +1,21 @@ +namespaced.js(8,12): error TS2702: 'NS' only refers to a type, but is being used as a namespace here. +namespaced.js(8,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. + + +==== namespaced.js (2 errors) ==== + /** + * @callback NS.Nested.Inner + * @param {Object} space - spaaaaaaaaace + * @param {Object} peace - peaaaaaaaaace + * @return {string | number} + */ + var x = 1; + /** @type {NS.Nested.Inner} */ + ~~ +!!! error TS2702: 'NS' only refers to a type, but is being used as a namespace here. + ~~~~~~~~~~~~~~~ +!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. + function f(space, peace) { + return '1' + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.errors.txt b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.errors.txt index 285e2ac7c4..b06d791748 100644 --- a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.errors.txt @@ -1,18 +1,22 @@ +test.js(3,17): error TS2322: Type 'number' is not assignable to type 'string'. test.js(5,14): error TS2322: Type 'number' is not assignable to type 'string'. test.js(7,5): error TS2322: Type '(x: number) => number' is not assignable to type '(x: number) => string'. Type 'number' is not assignable to type 'string'. +test.js(10,17): error TS2322: Type 'number' is not assignable to type 'string'. test.js(12,14): error TS2322: Type 'number' is not assignable to type 'string'. test.js(14,5): error TS2322: Type '(x: number) => number' is not assignable to type '(x: number) => string'. Type 'number' is not assignable to type 'string'. -test.js(24,5): error TS2322: Type 'number' is not assignable to type '0 | 1 | 2'. +test.js(28,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. test.js(34,5): error TS2322: Type '1 | 2' is not assignable to type '2 | 3'. Type '1' is not assignable to type '2 | 3'. -==== test.js (6 errors) ==== +==== test.js (8 errors) ==== // all 6 should error on return statement/expression /** @type {(x: number) => string} */ function h(x) { return x } + ~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. /** @type {(x: number) => string} */ var f = x => x ~ @@ -26,6 +30,8 @@ test.js(34,5): error TS2322: Type '1 | 2' is not assignable to type '2 | 3'. /** @type {{ (x: number): string }} */ function i(x) { return x } + ~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. /** @type {{ (x: number): string }} */ var j = x => x ~ @@ -46,12 +52,12 @@ test.js(34,5): error TS2322: Type '1 | 2' is not assignable to type '2 | 3'. /** @type {0 | 1 | 2} - assignment should not error */ var zeroonetwo = blargle('hi') - ~~~~~~~~~~ -!!! error TS2322: Type 'number' is not assignable to type '0 | 1 | 2'. /** @typedef {{(s: string): 0 | 1; (b: boolean): 2 | 3 }} Gioconda */ /** @type {Gioconda} */ + ~~~~~~~~ +!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. function monaLisa(sb) { return typeof sb === 'string' ? 1 : 2; } diff --git a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.types b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.types index e571cb95ec..c71a45abee 100644 --- a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.types +++ b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.types @@ -4,9 +4,9 @@ // all 6 should error on return statement/expression /** @type {(x: number) => string} */ function h(x) { return x } ->h : (x: any) => any ->x : any ->x : any +>h : (x: number) => string +>x : number +>x : number /** @type {(x: number) => string} */ var f = x => x @@ -24,9 +24,9 @@ var g = function (x) { return x } /** @type {{ (x: number): string }} */ function i(x) { return x } ->i : (x: any) => any ->x : any ->x : any +>i : (x: number) => string +>x : number +>x : number /** @type {{ (x: number): string }} */ var j = x => x @@ -46,8 +46,8 @@ var k = function (x) { return x } /** @typedef {(x: 'hi' | 'bye') => 0 | 1 | 2} Argle */ /** @type {Argle} */ function blargle(s) { ->blargle : (s: any) => number ->s : any +>blargle : (s: "bye" | "hi") => 0 | 1 | 2 +>s : "bye" | "hi" return 0; >0 : 0 @@ -56,8 +56,8 @@ function blargle(s) { /** @type {0 | 1 | 2} - assignment should not error */ var zeroonetwo = blargle('hi') >zeroonetwo : 0 | 1 | 2 ->blargle('hi') : number ->blargle : (s: any) => number +>blargle('hi') : 0 | 1 | 2 +>blargle : (s: "bye" | "hi") => 0 | 1 | 2 >'hi' : "hi" /** @typedef {{(s: string): 0 | 1; (b: boolean): 2 | 3 }} Gioconda */ diff --git a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.errors.txt b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.errors.txt index 34a62935d5..efd1d9904c 100644 --- a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.errors.txt @@ -1,12 +1,18 @@ +test.js(1,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. test.js(7,5): error TS2322: Type '(prop: any) => void' is not assignable to type '{ prop: string; }'. +test.js(10,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. +test.js(23,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. test.js(27,7): error TS2322: Type '(more: any) => void' is not assignable to type '() => void'. Target signature provides too few arguments. Expected 1 or more, but got 0. test.js(30,7): error TS2322: Type '(more: any) => void' is not assignable to type '() => void'. Target signature provides too few arguments. Expected 1 or more, but got 0. +test.js(33,14): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. -==== test.js (3 errors) ==== +==== test.js (7 errors) ==== /** @type {number} */ + ~~~~~~ +!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. function f() { return 1 } @@ -18,6 +24,8 @@ test.js(30,7): error TS2322: Type '(more: any) => void' is not assignable to typ } /** @type {(a: number) => number} */ + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. function add1(a, b) { return a + b; } /** @type {(a: number, b: number) => number} */ @@ -31,6 +39,8 @@ test.js(30,7): error TS2322: Type '(more: any) => void' is not assignable to typ // They can't have more parameters than the type/context. /** @type {() => void} */ + ~~~~~~~~~~ +!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. function funcWithMoreParameters(more) {} // error /** @type {() => void} */ @@ -47,6 +57,8 @@ test.js(30,7): error TS2322: Type '(more: any) => void' is not assignable to typ ({ /** @type {() => void} */ + ~~~~~~~~~~ +!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. methodWithMoreParameters(more) {}, // error }); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.types b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.types index 9b22414ac2..0d78ca717a 100644 --- a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.types +++ b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.types @@ -18,31 +18,31 @@ var g = function (prop) { /** @type {(a: number) => number} */ function add1(a, b) { return a + b; } ->add1 : (a: any, b: any) => any ->a : any +>add1 : (a: number, b: any) => number +>a : number >b : any >a + b : any ->a : any +>a : number >b : any /** @type {(a: number, b: number) => number} */ function add2(a, b) { return a + b; } ->add2 : (a: any, b: any) => any ->a : any ->b : any ->a + b : any ->a : any ->b : any +>add2 : (a: number, b: number) => number +>a : number +>b : number +>a + b : number +>a : number +>b : number // TODO: Should be an error since signature doesn't match. /** @type {(a: number, b: number, c: number) => number} */ function add3(a, b) { return a + b; } ->add3 : (a: any, b: any) => any ->a : any ->b : any ->a + b : any ->a : any ->b : any +>add3 : (a: number, b: number) => number +>a : number +>b : number +>a + b : number +>a : number +>b : number // Confirm initializers are compatible. // They can't have more parameters than the type/context. @@ -65,12 +65,12 @@ const arrowWithMoreParameters = (more) => {}; // error >more : any ({ ->({ /** @type {() => void} */ methodWithMoreParameters(more) {}, // error}) : { methodWithMoreParameters(more: any): void; } ->{ /** @type {() => void} */ methodWithMoreParameters(more) {}, // error} : { methodWithMoreParameters(more: any): void; } +>({ /** @type {() => void} */ methodWithMoreParameters(more) {}, // error}) : { methodWithMoreParameters(): void; } +>{ /** @type {() => void} */ methodWithMoreParameters(more) {}, // error} : { methodWithMoreParameters(): void; } /** @type {() => void} */ methodWithMoreParameters(more) {}, // error ->methodWithMoreParameters : (more: any) => void +>methodWithMoreParameters : () => void >more : any }); diff --git a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag7.types b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag7.types index d1ecda7ac4..25ffbdd7c0 100644 --- a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag7.types +++ b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag7.types @@ -10,9 +10,9 @@ class C { /** @type {Foo} */ foo(a, b) {} ->foo : (a: any, b: any) => void ->a : any ->b : any +>foo : (a: string, b: number) => void +>a : string +>b : number /** @type {(optional?) => void} */ methodWithOptionalParameters() {} diff --git a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTagOnObjectProperty1.errors.txt b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTagOnObjectProperty1.errors.txt index 35c7d11f52..0de428dba4 100644 --- a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTagOnObjectProperty1.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTagOnObjectProperty1.errors.txt @@ -1,7 +1,9 @@ +0.js(8,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'? +0.js(8,14): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. 0.js(16,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'? -==== 0.js (1 errors) ==== +==== 0.js (3 errors) ==== // @ts-check var lol = "hello Lol" const obj = { @@ -10,6 +12,11 @@ /** @type {string|undefined} */ bar: "42", /** @type {function(number): number} */ + ~~~~~~~~ +!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'? +!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here. + ~~~~~~~~ +!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. method1(n1) { return n1 + 42; }, diff --git a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTagOnObjectProperty2.errors.txt b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTagOnObjectProperty2.errors.txt index 0eb1d13321..42e3fc5e74 100644 --- a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTagOnObjectProperty2.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTagOnObjectProperty2.errors.txt @@ -1,9 +1,11 @@ 0.js(5,3): error TS2322: Type 'number' is not assignable to type 'string'. +0.js(6,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'? +0.js(6,14): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. 0.js(10,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'? 0.js(12,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'? -==== 0.js (3 errors) ==== +==== 0.js (5 errors) ==== // @ts-check var lol; const obj = { @@ -12,6 +14,11 @@ ~~~~~~~ !!! error TS2322: Type 'number' is not assignable to type 'string'. /** @type {function(number): number} */ + ~~~~~~~~ +!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'? +!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here. + ~~~~~~~~ +!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. method1(n1) { return "42"; }, diff --git a/testdata/baselines/reference/submodule/conformance/errorOnFunctionReturnType.errors.txt b/testdata/baselines/reference/submodule/conformance/errorOnFunctionReturnType.errors.txt index ba00327c67..32e7e83079 100644 --- a/testdata/baselines/reference/submodule/conformance/errorOnFunctionReturnType.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/errorOnFunctionReturnType.errors.txt @@ -1,16 +1,24 @@ +foo.js(6,12): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. +foo.js(13,5): error TS2322: Type 'string' is not assignable to type 'number'. +foo.js(16,31): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. foo.js(21,5): error TS2322: Type '() => void' is not assignable to type 'FunctionReturningPromise'. Type 'void' is not assignable to type 'Promise'. +foo.js(30,12): error TS2534: A function returning 'never' cannot have a reachable end point. +foo.js(37,5): error TS2322: Type '"asd"' is not assignable to type 'never'. +foo.js(40,29): error TS2534: A function returning 'never' cannot have a reachable end point. foo.js(45,5): error TS2322: Type '() => void' is not assignable to type 'FunctionReturningNever'. Type 'void' is not assignable to type 'never'. -==== foo.js (2 errors) ==== +==== foo.js (8 errors) ==== /** * @callback FunctionReturningPromise * @returns {Promise} */ /** @type {FunctionReturningPromise} */ + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. function testPromise1() { console.log("Nope"); } @@ -18,9 +26,13 @@ foo.js(45,5): error TS2322: Type '() => void' is not assignable to type 'Functio /** @type {FunctionReturningPromise} */ async function testPromise2() { return "asd"; + ~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. } var testPromise3 = /** @type {FunctionReturningPromise} */ function() { + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. console.log("test") } @@ -38,6 +50,8 @@ foo.js(45,5): error TS2322: Type '() => void' is not assignable to type 'Functio */ /** @type {FunctionReturningNever} */ + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2534: A function returning 'never' cannot have a reachable end point. function testNever1() { } @@ -45,9 +59,13 @@ foo.js(45,5): error TS2322: Type '() => void' is not assignable to type 'Functio /** @type {FunctionReturningNever} */ async function testNever2() { return "asd"; + ~~~~~~ +!!! error TS2322: Type '"asd"' is not assignable to type 'never'. } var testNever3 = /** @type {FunctionReturningNever} */ function() { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2534: A function returning 'never' cannot have a reachable end point. console.log("test") } diff --git a/testdata/baselines/reference/submodule/conformance/errorOnFunctionReturnType.types b/testdata/baselines/reference/submodule/conformance/errorOnFunctionReturnType.types index 4a72817f54..885d95e033 100644 --- a/testdata/baselines/reference/submodule/conformance/errorOnFunctionReturnType.types +++ b/testdata/baselines/reference/submodule/conformance/errorOnFunctionReturnType.types @@ -8,7 +8,7 @@ /** @type {FunctionReturningPromise} */ function testPromise1() { ->testPromise1 : () => void +>testPromise1 : () => Promise console.log("Nope"); >console.log("Nope") : void @@ -20,15 +20,15 @@ function testPromise1() { /** @type {FunctionReturningPromise} */ async function testPromise2() { ->testPromise2 : () => Promise +>testPromise2 : () => Promise return "asd"; >"asd" : "asd" } var testPromise3 = /** @type {FunctionReturningPromise} */ function() { ->testPromise3 : () => void ->function() { console.log("test")} : () => void +>testPromise3 : () => Promise +>function() { console.log("test")} : () => Promise console.log("test") >console.log("test") : void @@ -58,21 +58,21 @@ var testPromise4 = function() { /** @type {FunctionReturningNever} */ function testNever1() { ->testNever1 : () => void +>testNever1 : () => never } /** @type {FunctionReturningNever} */ async function testNever2() { ->testNever2 : () => Promise +>testNever2 : () => never return "asd"; >"asd" : "asd" } var testNever3 = /** @type {FunctionReturningNever} */ function() { ->testNever3 : () => void ->function() { console.log("test")} : () => void +>testNever3 : () => never +>function() { console.log("test")} : () => never console.log("test") >console.log("test") : void diff --git a/testdata/baselines/reference/submodule/conformance/jsdocFunctionType.errors.txt b/testdata/baselines/reference/submodule/conformance/jsdocFunctionType.errors.txt index bed5688d1f..b1407448a2 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocFunctionType.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/jsdocFunctionType.errors.txt @@ -8,10 +8,9 @@ functions.js(31,19): error TS7006: Parameter 'ab' implicitly has an 'any' type. functions.js(31,23): error TS7006: Parameter 'onetwo' implicitly has an 'any' type. functions.js(49,13): error TS2749: 'D' refers to a value, but is being used as a type here. Did you mean 'typeof D'? functions.js(51,26): error TS7006: Parameter 'dref' implicitly has an 'any' type. -functions.js(72,14): error TS7019: Rest parameter 'args' implicitly has an 'any[]' type. -==== functions.js (11 errors) ==== +==== functions.js (10 errors) ==== /** * @param {function(this: string, number): number} c is just passing on through * @return {function(this: string, number): number} @@ -107,8 +106,6 @@ functions.js(72,14): error TS7019: Rest parameter 'args' implicitly has an 'any[ * @type {(...args: [string, string] | [number, string, string]) => void} */ function foo(...args) { - ~~~~~~~ -!!! error TS7019: Rest parameter 'args' implicitly has an 'any[]' type. args; } diff --git a/testdata/baselines/reference/submodule/conformance/jsdocFunctionType.types b/testdata/baselines/reference/submodule/conformance/jsdocFunctionType.types index c58ccc8fdc..bc6bece591 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocFunctionType.types +++ b/testdata/baselines/reference/submodule/conformance/jsdocFunctionType.types @@ -173,22 +173,22 @@ var y3 = id2(E); * @type {(...args: [string, string] | [number, string, string]) => void} */ function foo(...args) { ->foo : (...args: any[]) => void ->args : any[] +>foo : (...args: [string, string] | [number, string, string]) => void +>args : [string, string] | [number, string, string] args; ->args : any[] +>args : [string, string] | [number, string, string] } foo('abc', 'def'); >foo('abc', 'def') : void ->foo : (...args: any[]) => void +>foo : (...args: [string, string] | [number, string, string]) => void >'abc' : "abc" >'def' : "def" foo(42, 'abc', 'def'); >foo(42, 'abc', 'def') : void ->foo : (...args: any[]) => void +>foo : (...args: [string, string] | [number, string, string]) => void >42 : 42 >'abc' : "abc" >'def' : "def" diff --git a/testdata/baselines/reference/submodule/conformance/jsdocFunction_missingReturn.errors.txt b/testdata/baselines/reference/submodule/conformance/jsdocFunction_missingReturn.errors.txt new file mode 100644 index 0000000000..cf99dc4aac --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/jsdocFunction_missingReturn.errors.txt @@ -0,0 +1,13 @@ +/a.js(1,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'? +/a.js(1,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. + + +==== /a.js (2 errors) ==== + /** @type {function(): number} */ + ~~~~~~~~ +!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'? +!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here. + ~~~~~~~~ +!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. + function f() {} + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsdocThisType.errors.txt b/testdata/baselines/reference/submodule/conformance/jsdocThisType.errors.txt index 94ee1d5f47..1d0065669f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocThisType.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/jsdocThisType.errors.txt @@ -1,6 +1,10 @@ /a.js(3,10): error TS2339: Property 'test' does not exist on type 'Foo'. +/a.js(8,10): error TS2339: Property 'test' does not exist on type 'Foo'. /a.js(13,10): error TS2339: Property 'test' does not exist on type 'Foo'. +/a.js(18,10): error TS2339: Property 'test' does not exist on type 'Foo'. /a.js(21,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'? +/a.js(26,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'? +/a.js(26,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. ==== /types.d.ts (0 errors) ==== @@ -10,7 +14,7 @@ export type M = (this: Foo) => void; -==== /a.js (3 errors) ==== +==== /a.js (7 errors) ==== /** @type {import('./types').M} */ export const f1 = function() { this.test(); @@ -21,6 +25,8 @@ /** @type {import('./types').M} */ export function f2() { this.test(); + ~~~~ +!!! error TS2339: Property 'test' does not exist on type 'Foo'. } /** @type {(this: import('./types').Foo) => void} */ @@ -33,6 +39,8 @@ /** @type {(this: import('./types').Foo) => void} */ export function f4() { this.test(); + ~~~~ +!!! error TS2339: Property 'test' does not exist on type 'Foo'. } /** @type {function(this: import('./types').Foo): void} */ @@ -44,6 +52,11 @@ } /** @type {function(this: import('./types').Foo): void} */ + ~~~~~~~~ +!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'? +!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here. + ~~~~~~~~ +!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. export function f6() { this.test(); } diff --git a/testdata/baselines/reference/submodule/conformance/jsdocThisType.symbols b/testdata/baselines/reference/submodule/conformance/jsdocThisType.symbols index f9fd5bc328..c0c8f8d8ec 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocThisType.symbols +++ b/testdata/baselines/reference/submodule/conformance/jsdocThisType.symbols @@ -27,6 +27,7 @@ export function f2() { >f2 : Symbol(f2, Decl(a.js, 3, 1)) this.test(); +>this : Symbol(Foo, Decl(types.d.ts, 0, 0)) } /** @type {(this: import('./types').Foo) => void} */ @@ -42,6 +43,7 @@ export function f4() { >f4 : Symbol(f4, Decl(a.js, 13, 1)) this.test(); +>this : Symbol(Foo, Decl(types.d.ts, 0, 0)) } /** @type {function(this: import('./types').Foo): void} */ diff --git a/testdata/baselines/reference/submodule/conformance/jsdocThisType.symbols.diff b/testdata/baselines/reference/submodule/conformance/jsdocThisType.symbols.diff index 0f34a5f3b7..41d72e433d 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocThisType.symbols.diff +++ b/testdata/baselines/reference/submodule/conformance/jsdocThisType.symbols.diff @@ -9,23 +9,7 @@ } export type M = (this: Foo) => void; -@@= skipped -22, +22 lines =@@ - >f2 : Symbol(f2, Decl(a.js, 3, 1)) - - this.test(); -->this : Symbol(Foo, Decl(types.d.ts, 0, 0)) - } - - /** @type {(this: import('./types').Foo) => void} */ -@@= skipped -16, +15 lines =@@ - >f4 : Symbol(f4, Decl(a.js, 13, 1)) - - this.test(); -->this : Symbol(Foo, Decl(types.d.ts, 0, 0)) - } - - /** @type {function(this: import('./types').Foo): void} */ -@@= skipped -8, +7 lines =@@ +@@= skipped -46, +46 lines =@@ >f5 : Symbol(f5, Decl(a.js, 21, 12)) this.test(); diff --git a/testdata/baselines/reference/submodule/conformance/jsdocThisType.types b/testdata/baselines/reference/submodule/conformance/jsdocThisType.types index 9a335ab3cb..3070063327 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocThisType.types +++ b/testdata/baselines/reference/submodule/conformance/jsdocThisType.types @@ -30,7 +30,7 @@ export function f2() { this.test(); >this.test() : any >this.test : any ->this : any +>this : import("./types").Foo >test : any } @@ -53,7 +53,7 @@ export function f4() { this.test(); >this.test() : any >this.test : any ->this : any +>this : import("./types").Foo >test : any } diff --git a/testdata/baselines/reference/submodule/conformance/jsdocTypeTagParameterType.errors.txt b/testdata/baselines/reference/submodule/conformance/jsdocTypeTagParameterType.errors.txt index 4b79a3d468..c7dad2e526 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocTypeTagParameterType.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/jsdocTypeTagParameterType.errors.txt @@ -1,6 +1,6 @@ a.js(1,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'? a.js(2,12): error TS7006: Parameter 'value' implicitly has an 'any' type. -a.js(6,12): error TS7006: Parameter 's' implicitly has an 'any' type. +a.js(7,5): error TS2322: Type 'number' is not assignable to type 'string'. ==== a.js (3 errors) ==== @@ -15,8 +15,8 @@ a.js(6,12): error TS7006: Parameter 's' implicitly has an 'any' type. }; /** @type {(s: string) => void} */ function g(s) { - ~ -!!! error TS7006: Parameter 's' implicitly has an 'any' type. s = 1 // Should error + ~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsdocTypeTagParameterType.types b/testdata/baselines/reference/submodule/conformance/jsdocTypeTagParameterType.types index fc9b78da8e..0a618e3415 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocTypeTagParameterType.types +++ b/testdata/baselines/reference/submodule/conformance/jsdocTypeTagParameterType.types @@ -15,12 +15,12 @@ const f = (value) => { }; /** @type {(s: string) => void} */ function g(s) { ->g : (s: any) => void ->s : any +>g : (s: string) => void +>s : string s = 1 // Should error >s = 1 : 1 ->s : any +>s : string >1 : 1 } diff --git a/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.errors.txt b/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.errors.txt index 96a1ffda77..5b78db63ce 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.errors.txt @@ -1,12 +1,10 @@ a.js(1,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'? a.js(2,12): error TS7006: Parameter 'value' implicitly has an 'any' type. -a.js(5,12): error TS7006: Parameter 's' implicitly has an 'any' type. -a.js(8,12): error TS7006: Parameter 's' implicitly has an 'any' type. a.js(12,1): error TS2554: Expected 1 arguments, but got 0. a.js(13,1): error TS2554: Expected 1 arguments, but got 0. -==== a.js (6 errors) ==== +==== a.js (4 errors) ==== /** @type {function(string): void} */ ~~~~~~~~ !!! error TS2552: Cannot find name 'function'. Did you mean 'Function'? @@ -17,13 +15,9 @@ a.js(13,1): error TS2554: Expected 1 arguments, but got 0. }; /** @type {(s: string) => void} */ function g(s) { - ~ -!!! error TS7006: Parameter 's' implicitly has an 'any' type. } /** @type {{(s: string): void}} */ function h(s) { - ~ -!!! error TS7006: Parameter 's' implicitly has an 'any' type. } f() // should error diff --git a/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.types b/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.types index 9c3065edcb..9ac7691ddc 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.types +++ b/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.types @@ -10,13 +10,13 @@ const f = (value) => { }; /** @type {(s: string) => void} */ function g(s) { ->g : (s: any) => void ->s : any +>g : (s: string) => void +>s : string } /** @type {{(s: string): void}} */ function h(s) { ->h : (s: any) => void ->s : any +>h : (s: string) => void +>s : string } f() // should error @@ -25,9 +25,9 @@ f() // should error g() // should error >g() : void ->g : (s: any) => void +>g : (s: string) => void h() >h() : void ->h : (s: any) => void +>h : (s: string) => void diff --git a/testdata/baselines/reference/submodule/conformance/returnTagTypeGuard.types b/testdata/baselines/reference/submodule/conformance/returnTagTypeGuard.types index d3bd4e3d68..c74bd04923 100644 --- a/testdata/baselines/reference/submodule/conformance/returnTagTypeGuard.types +++ b/testdata/baselines/reference/submodule/conformance/returnTagTypeGuard.types @@ -109,11 +109,11 @@ function foo(val) { /** @type {Cb} */ function isNumber(x) { return typeof x === "number" } ->isNumber : (x: any) => x is number ->x : any +>isNumber : (x: unknown) => x is number +>x : unknown >typeof x === "number" : boolean >typeof x : "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined" ->x : any +>x : unknown >"number" : "number" /** @param {unknown} x */ @@ -123,7 +123,7 @@ function g(x) { if (isNumber(x)) { >isNumber(x) : boolean ->isNumber : (x: any) => x is number +>isNumber : (x: unknown) => x is number >x : unknown x * 2; diff --git a/testdata/baselines/reference/submodule/conformance/typeFromJSInitializer3.errors.txt b/testdata/baselines/reference/submodule/conformance/typeFromJSInitializer3.errors.txt deleted file mode 100644 index 6d2d4d0bf9..0000000000 --- a/testdata/baselines/reference/submodule/conformance/typeFromJSInitializer3.errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -a.js(2,10): error TS7010: 'f1', which lacks return-type annotation, implicitly has an 'any' return type. -a.js(8,10): error TS7010: 'f2', which lacks return-type annotation, implicitly has an 'any' return type. - - -==== a.js (2 errors) ==== - /** @type {() => undefined} */ - function f1() { - ~~ -!!! error TS7010: 'f1', which lacks return-type annotation, implicitly has an 'any' return type. - return undefined; - } - const a = f1() - - /** @type {() => null} */ - function f2() { - ~~ -!!! error TS7010: 'f2', which lacks return-type annotation, implicitly has an 'any' return type. - return null; - } - const b = f2() - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeFromJSInitializer3.types b/testdata/baselines/reference/submodule/conformance/typeFromJSInitializer3.types index 8fc0d4fc8e..20f375ec24 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromJSInitializer3.types +++ b/testdata/baselines/reference/submodule/conformance/typeFromJSInitializer3.types @@ -3,24 +3,24 @@ === a.js === /** @type {() => undefined} */ function f1() { ->f1 : () => any +>f1 : () => undefined return undefined; >undefined : undefined } const a = f1() ->a : any ->f1() : any ->f1 : () => any +>a : undefined +>f1() : undefined +>f1 : () => undefined /** @type {() => null} */ function f2() { ->f2 : () => any +>f2 : () => null return null; } const b = f2() ->b : any ->f2() : any ->f2 : () => any +>b : null +>f2() : null +>f2 : () => null diff --git a/testdata/baselines/reference/submodule/conformance/typeTagCircularReferenceOnConstructorFunction.errors.txt b/testdata/baselines/reference/submodule/conformance/typeTagCircularReferenceOnConstructorFunction.errors.txt new file mode 100644 index 0000000000..6dbb7500aa --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/typeTagCircularReferenceOnConstructorFunction.errors.txt @@ -0,0 +1,15 @@ +bug27346.js(2,11): error TS2749: 'MyClass' refers to a value, but is being used as a type here. Did you mean 'typeof MyClass'? +bug27346.js(2,11): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. + + +==== bug27346.js (2 errors) ==== + /** + * @type {MyClass} + ~~~~~~~ +!!! error TS2749: 'MyClass' refers to a value, but is being used as a type here. Did you mean 'typeof MyClass'? + ~~~~~~~ +!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. + */ + function MyClass() { } + MyClass.prototype = {}; + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.js b/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.js index 1cd771088e..de1d469b27 100644 --- a/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.js +++ b/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.js @@ -43,4 +43,4 @@ export type IFn = (m: T) => T; * @typedef {(m : T) => T} IFn */ /**@type {IFn}*/ -export declare function inJs(l: any): any; +export declare function inJs(l: T): T; diff --git a/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.js.diff b/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.js.diff index 678958065c..4c7d4f17b7 100644 --- a/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.js.diff @@ -25,4 +25,4 @@ + * @typedef {(m : T) => T} IFn + */ +/**@type {IFn}*/ -+export declare function inJs(l: any): any; \ No newline at end of file ++export declare function inJs(l: T): T; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.types b/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.types index 4b523d5efb..73284b3c14 100644 --- a/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.types +++ b/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.types @@ -7,15 +7,15 @@ /**@type {IFn}*/ export function inJs(l) { ->inJs : (l: any) => any ->l : any +>inJs : (l: T) => T +>l : T return l; ->l : any +>l : T } inJs(1); // lints error. Why? ->inJs(1) : any ->inJs : (l: any) => any +>inJs(1) : 1 +>inJs : (l: T) => T >1 : 1 /**@type {IFn}*/ diff --git a/testdata/baselines/reference/submodule/conformance/typeTagWithGenericSignature.errors.txt b/testdata/baselines/reference/submodule/conformance/typeTagWithGenericSignature.errors.txt deleted file mode 100644 index 9e092ef041..0000000000 --- a/testdata/baselines/reference/submodule/conformance/typeTagWithGenericSignature.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -bug25618.js(2,16): error TS7006: Parameter 'param' implicitly has an 'any' type. - - -==== bug25618.js (1 errors) ==== - /** @type {(param?: T) => T | undefined} */ - function typed(param) { - ~~~~~ -!!! error TS7006: Parameter 'param' implicitly has an 'any' type. - return param; - } - - var n = typed(1); - - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeTagWithGenericSignature.types b/testdata/baselines/reference/submodule/conformance/typeTagWithGenericSignature.types index f6bfe9cbcf..f914e5dd2e 100644 --- a/testdata/baselines/reference/submodule/conformance/typeTagWithGenericSignature.types +++ b/testdata/baselines/reference/submodule/conformance/typeTagWithGenericSignature.types @@ -3,17 +3,17 @@ === bug25618.js === /** @type {(param?: T) => T | undefined} */ function typed(param) { ->typed : (param: any) => any ->param : any +>typed : (param: T | undefined) => T | undefined +>param : T | undefined return param; ->param : any +>param : T | undefined } var n = typed(1); ->n : any ->typed(1) : any ->typed : (param: any) => any +>n : number | undefined +>typed(1) : 1 | undefined +>typed : (param: T | undefined) => T | undefined >1 : 1 diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/jsdocBracelessTypeTag1.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/jsdocBracelessTypeTag1.errors.txt.diff deleted file mode 100644 index 7c77099eea..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/compiler/jsdocBracelessTypeTag1.errors.txt.diff +++ /dev/null @@ -1,26 +0,0 @@ ---- old.jsdocBracelessTypeTag1.errors.txt -+++ new.jsdocBracelessTypeTag1.errors.txt -@@= skipped -0, +0 lines =@@ --index.js(3,3): error TS2322: Type 'number' is not assignable to type 'string'. -+index.js(12,14): error TS7006: Parameter 'arg' implicitly has an 'any' type. - index.js(20,16): error TS2322: Type '"other"' is not assignable to type '"bar" | "foo"'. - - -@@= skipped -5, +5 lines =@@ - /** @type () => string */ - function fn1() { - return 42; -- ~~~~~~ --!!! error TS2322: Type 'number' is not assignable to type 'string'. - } - - /** @type () => string */ -@@= skipped -11, +9 lines =@@ - - /** @type (arg: string) => string */ - function fn3(arg) { -+ ~~~ -+!!! error TS7006: Parameter 'arg' implicitly has an 'any' type. - return arg; - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/jsdocBracelessTypeTag1.types.diff b/testdata/baselines/reference/submoduleAccepted/compiler/jsdocBracelessTypeTag1.types.diff deleted file mode 100644 index da3cdb69e7..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/compiler/jsdocBracelessTypeTag1.types.diff +++ /dev/null @@ -1,26 +0,0 @@ ---- old.jsdocBracelessTypeTag1.types -+++ new.jsdocBracelessTypeTag1.types -@@= skipped -2, +2 lines =@@ - === index.js === - /** @type () => string */ - function fn1() { -->fn1 : () => string -+>fn1 : () => number - - return 42; - >42 : 42 -@@= skipped -16, +16 lines =@@ - - /** @type (arg: string) => string */ - function fn3(arg) { -->fn3 : (arg: string) => string -->arg : string -+>fn3 : (arg: any) => any -+>arg : any - - return arg; -->arg : string -+>arg : any - } - - /** @type ({ type: 'foo' } | { type: 'bar' }) & { prop: number } */ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.errors.txt.diff index fe7011b1d5..b30aabfac8 100644 --- a/testdata/baselines/reference/submoduleAccepted/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.errors.txt.diff @@ -2,7 +2,6 @@ +++ new.moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.errors.txt @@= skipped -0, +0 lines =@@ - -+typescript-eslint.js(12,17): error TS7019: Rest parameter 'configs' implicitly has an 'any[]' type. +typescript-eslint.js(14,1): error TS2309: An export assignment cannot be used in a module with other exported elements. + + @@ -30,7 +29,7 @@ + }, + }; + -+==== typescript-eslint.js (2 errors) ==== ++==== typescript-eslint.js (1 errors) ==== + /** + * @typedef {{ rules: Record }} Plugin + */ @@ -43,8 +42,6 @@ + * @type {(...configs: Config[]) => void} + */ + function config(...configs) { } -+ ~~~~~~~~~~ -+!!! error TS7019: Rest parameter 'configs' implicitly has an 'any[]' type. + + module.exports = { config }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.types.diff b/testdata/baselines/reference/submoduleAccepted/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.types.diff index 215c288fd9..45488af1c8 100644 --- a/testdata/baselines/reference/submoduleAccepted/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.types.diff @@ -14,8 +14,8 @@ const tseslint = require('./typescript-eslint.js'); ->tseslint : typeof tseslint ->require('./typescript-eslint.js') : typeof tseslint -+>tseslint : { config: (...configs: any[]) => void; } -+>require('./typescript-eslint.js') : { config: (...configs: any[]) => void; } ++>tseslint : { config: (...configs: import("./typescript-eslint.js").Config[]) => void; } ++>require('./typescript-eslint.js') : { config: (...configs: import("./typescript-eslint.js").Config[]) => void; } >require : any >'./typescript-eslint.js' : "./typescript-eslint.js" @@ -25,9 +25,9 @@ ->tseslint : typeof tseslint ->config : (...configs: Config[]) => void ->eslintReact : { plugins: { react: { deprecatedRules: { "jsx-sort-default-props": boolean; }; rules: { 'no-unsafe': boolean; }; }; }; } -+>tseslint.config : (...configs: any[]) => void -+>tseslint : { config: (...configs: any[]) => void; } -+>config : (...configs: any[]) => void ++>tseslint.config : (...configs: import("./typescript-eslint.js").Config[]) => void ++>tseslint : { config: (...configs: import("./typescript-eslint.js").Config[]) => void; } ++>config : (...configs: import("./typescript-eslint.js").Config[]) => void +>eslintReact : { plugins: { react: { deprecatedRules: { "jsx-sort-default-props": boolean; }; rules: { "no-unsafe": boolean; }; }; }; } === eslint-plugin-react.js === @@ -81,25 +81,17 @@ }, }, -@@= skipped -38, +38 lines =@@ - * @type {(...configs: Config[]) => void} - */ - function config(...configs) { } -->config : (...configs: Config[]) => void -->configs : Config[] -+>config : (...configs: any[]) => void -+>configs : any[] +@@= skipped -42, +42 lines =@@ + >configs : Config[] module.exports = { config }; ->module.exports = { config } : typeof module.exports ->module.exports : typeof module.exports ->module : { exports: typeof module.exports; } ->exports : typeof module.exports -->{ config } : { config: (...configs: Config[]) => void; } -->config : (...configs: Config[]) => void -+>module.exports = { config } : { config: (...configs: any[]) => void; } -+>module.exports : { config: (...configs: any[]) => void; } -+>module : { "export=": { config: (...configs: any[]) => void; }; } -+>exports : { config: (...configs: any[]) => void; } -+>{ config } : { config: (...configs: any[]) => void; } -+>config : (...configs: any[]) => void ++>module.exports = { config } : { config: (...configs: Config[]) => void; } ++>module.exports : { config: (...configs: Config[]) => void; } ++>module : { "export=": { config: (...configs: Config[]) => void; }; } ++>exports : { config: (...configs: Config[]) => void; } + >{ config } : { config: (...configs: Config[]) => void; } + >config : (...configs: Config[]) => void diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/assertionsAndNonReturningFunctions.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/assertionsAndNonReturningFunctions.types.diff index b4d7a603e3..3cc62ab9f7 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/assertionsAndNonReturningFunctions.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/assertionsAndNonReturningFunctions.types.diff @@ -8,41 +8,4 @@ +>check => { if (!check) throw new Error();} : (check: boolean) => void >check : boolean - if (!check) throw new Error(); -@@= skipped -12, +12 lines =@@ - - /** @type {(x: unknown) => asserts x is string } */ - function assertIsString(x) { -->assertIsString : (x: unknown) => asserts x is string -->x : unknown -+>assertIsString : (x: any) => void -+>x : any - - if (!(typeof x === "string")) throw new Error(); - >!(typeof x === "string") : boolean - >(typeof x === "string") : boolean - >typeof x === "string" : boolean - >typeof x : "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined" -->x : unknown -+>x : any - >"string" : "string" - >new Error() : Error - >Error : ErrorConstructor -@@= skipped -90, +90 lines =@@ - - assertIsString(x); - >assertIsString(x) : void -->assertIsString : (x: unknown) => asserts x is string -+>assertIsString : (x: any) => void - >x : any - - x.length; -->x.length : number -->x : string -->length : number -+>x.length : any -+>x : any -+>length : any - } - if (!!true) { - >!!true : boolean \ No newline at end of file + if (!check) throw new Error(); \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/callbackTagNamespace.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/callbackTagNamespace.errors.txt.diff new file mode 100644 index 0000000000..7379d9de9f --- /dev/null +++ b/testdata/baselines/reference/submoduleAccepted/conformance/callbackTagNamespace.errors.txt.diff @@ -0,0 +1,25 @@ +--- old.callbackTagNamespace.errors.txt ++++ new.callbackTagNamespace.errors.txt +@@= skipped -0, +0 lines =@@ +- ++namespaced.js(8,12): error TS2702: 'NS' only refers to a type, but is being used as a namespace here. ++namespaced.js(8,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. ++ ++ ++==== namespaced.js (2 errors) ==== ++ /** ++ * @callback NS.Nested.Inner ++ * @param {Object} space - spaaaaaaaaace ++ * @param {Object} peace - peaaaaaaaaace ++ * @return {string | number} ++ */ ++ var x = 1; ++ /** @type {NS.Nested.Inner} */ ++ ~~ ++!!! error TS2702: 'NS' only refers to a type, but is being used as a namespace here. ++ ~~~~~~~~~~~~~~~ ++!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. ++ function f(space, peace) { ++ return '1' ++ } ++ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.errors.txt.diff index c6f159b314..0c5e34cf97 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.errors.txt.diff @@ -1,30 +1,22 @@ --- old.checkJsdocTypeTag5.errors.txt +++ new.checkJsdocTypeTag5.errors.txt @@= skipped -0, +0 lines =@@ --test.js(3,17): error TS2322: Type 'number' is not assignable to type 'string'. + test.js(3,17): error TS2322: Type 'number' is not assignable to type 'string'. test.js(5,14): error TS2322: Type 'number' is not assignable to type 'string'. -test.js(7,24): error TS2322: Type 'number' is not assignable to type 'string'. --test.js(10,17): error TS2322: Type 'number' is not assignable to type 'string'. +test.js(7,5): error TS2322: Type '(x: number) => number' is not assignable to type '(x: number) => string'. + Type 'number' is not assignable to type 'string'. + test.js(10,17): error TS2322: Type 'number' is not assignable to type 'string'. test.js(12,14): error TS2322: Type 'number' is not assignable to type 'string'. -test.js(14,24): error TS2322: Type 'number' is not assignable to type 'string'. -test.js(28,12): error TS8030: The type of a function declaration must match the function's signature. +test.js(14,5): error TS2322: Type '(x: number) => number' is not assignable to type '(x: number) => string'. + Type 'number' is not assignable to type 'string'. -+test.js(24,5): error TS2322: Type 'number' is not assignable to type '0 | 1 | 2'. ++test.js(28,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. test.js(34,5): error TS2322: Type '1 | 2' is not assignable to type '2 | 3'. Type '1' is not assignable to type '2 | 3'. - --==== test.js (8 errors) ==== -+==== test.js (6 errors) ==== - // all 6 should error on return statement/expression - /** @type {(x: number) => string} */ - function h(x) { return x } -- ~~~~~~ --!!! error TS2322: Type 'number' is not assignable to type 'string'. - /** @type {(x: number) => string} */ +@@= skipped -18, +20 lines =@@ var f = x => x ~ !!! error TS2322: Type 'number' is not assignable to type 'string'. @@ -39,9 +31,7 @@ /** @type {{ (x: number): string }} */ function i(x) { return x } -- ~~~~~~ --!!! error TS2322: Type 'number' is not assignable to type 'string'. - /** @type {{ (x: number): string }} */ +@@= skipped -13, +15 lines =@@ var j = x => x ~ !!! error TS2322: Type 'number' is not assignable to type 'string'. @@ -56,18 +46,12 @@ /** @typedef {(x: 'hi' | 'bye') => 0 | 1 | 2} Argle */ -@@= skipped -45, +45 lines =@@ - - /** @type {0 | 1 | 2} - assignment should not error */ - var zeroonetwo = blargle('hi') -+ ~~~~~~~~~~ -+!!! error TS2322: Type 'number' is not assignable to type '0 | 1 | 2'. - - /** @typedef {{(s: string): 0 | 1; (b: boolean): 2 | 3 }} Gioconda */ +@@= skipped -19, +21 lines =@@ /** @type {Gioconda} */ -- ~~~~~~~~ + ~~~~~~~~ -!!! error TS8030: The type of a function declaration must match the function's signature. ++!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. function monaLisa(sb) { return typeof sb === 'string' ? 1 : 2; } \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.types.diff index b180c64c34..cb18606f8c 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.types.diff @@ -1,16 +1,6 @@ --- old.checkJsdocTypeTag5.types +++ new.checkJsdocTypeTag5.types -@@= skipped -3, +3 lines =@@ - // all 6 should error on return statement/expression - /** @type {(x: number) => string} */ - function h(x) { return x } -->h : (x: number) => string -->x : number -->x : number -+>h : (x: any) => any -+>x : any -+>x : any - +@@= skipped -10, +10 lines =@@ /** @type {(x: number) => string} */ var f = x => x >f : (x: number) => string @@ -27,15 +17,7 @@ >x : number >x : number - /** @type {{ (x: number): string }} */ - function i(x) { return x } -->i : (x: number) => string -->x : number -->x : number -+>i : (x: any) => any -+>x : any -+>x : any - +@@= skipped -20, +20 lines =@@ /** @type {{ (x: number): string }} */ var j = x => x >j : (x: number) => string @@ -52,25 +34,21 @@ >x : number >x : number -@@= skipped -42, +42 lines =@@ +@@= skipped -15, +15 lines =@@ /** @typedef {(x: 'hi' | 'bye') => 0 | 1 | 2} Argle */ /** @type {Argle} */ function blargle(s) { ->blargle : (x: "hi" | "bye") => 0 | 1 | 2 -->s : "bye" | "hi" -+>blargle : (s: any) => number -+>s : any ++>blargle : (s: "bye" | "hi") => 0 | 1 | 2 + >s : "bye" | "hi" return 0; - >0 : 0 -@@= skipped -10, +10 lines =@@ - /** @type {0 | 1 | 2} - assignment should not error */ +@@= skipped -11, +11 lines =@@ var zeroonetwo = blargle('hi') >zeroonetwo : 0 | 1 | 2 -->blargle('hi') : 0 | 1 | 2 + >blargle('hi') : 0 | 1 | 2 ->blargle : (x: "hi" | "bye") => 0 | 1 | 2 -+>blargle('hi') : number -+>blargle : (s: any) => number ++>blargle : (s: "bye" | "hi") => 0 | 1 | 2 >'hi' : "hi" /** @typedef {{(s: string): 0 | 1; (b: boolean): 2 | 3 }} Gioconda */ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.errors.txt.diff index 91b9e0af5b..cd947ab4c9 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.errors.txt.diff @@ -2,48 +2,53 @@ +++ new.checkJsdocTypeTag6.errors.txt @@= skipped -0, +0 lines =@@ -test.js(1,12): error TS8030: The type of a function declaration must match the function's signature. ++test.js(1,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. test.js(7,5): error TS2322: Type '(prop: any) => void' is not assignable to type '{ prop: string; }'. -test.js(10,12): error TS8030: The type of a function declaration must match the function's signature. -test.js(23,12): error TS8030: The type of a function declaration must match the function's signature. ++test.js(10,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. ++test.js(23,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. test.js(27,7): error TS2322: Type '(more: any) => void' is not assignable to type '() => void'. Target signature provides too few arguments. Expected 1 or more, but got 0. test.js(30,7): error TS2322: Type '(more: any) => void' is not assignable to type '() => void'. Target signature provides too few arguments. Expected 1 or more, but got 0. -test.js(34,3): error TS2322: Type '(more: any) => void' is not assignable to type '() => void'. - Target signature provides too few arguments. Expected 1 or more, but got 0. -- -- --==== test.js (7 errors) ==== -+ -+ -+==== test.js (3 errors) ==== ++test.js(33,14): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. + + + ==== test.js (7 errors) ==== /** @type {number} */ -- ~~~~~~ + ~~~~~~ -!!! error TS8030: The type of a function declaration must match the function's signature. ++!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. function f() { return 1 } -@@= skipped -24, +17 lines =@@ - } +@@= skipped -25, +24 lines =@@ /** @type {(a: number) => number} */ -- ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS8030: The type of a function declaration must match the function's signature. ++!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. function add1(a, b) { return a + b; } /** @type {(a: number, b: number) => number} */ -@@= skipped -15, +13 lines =@@ - // They can't have more parameters than the type/context. +@@= skipped -15, +15 lines =@@ /** @type {() => void} */ -- ~~~~~~~~~~ + ~~~~~~~~~~ -!!! error TS8030: The type of a function declaration must match the function's signature. ++!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. function funcWithMoreParameters(more) {} // error /** @type {() => void} */ -@@= skipped -19, +17 lines =@@ +@@= skipped -17, +17 lines =@@ + ({ /** @type {() => void} */ ++ ~~~~~~~~~~ ++!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. methodWithMoreParameters(more) {}, // error - ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '(more: any) => void' is not assignable to type '() => void'. diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.types.diff index cbc89bee12..18a4844033 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.types.diff @@ -5,48 +5,20 @@ /** @type {(a: number) => number} */ function add1(a, b) { return a + b; } ->add1 : (a: number) => number -->a : number -+>add1 : (a: any, b: any) => any -+>a : any ++>add1 : (a: number, b: any) => number + >a : number >b : any >a + b : any -->a : number -+>a : any - >b : any - - /** @type {(a: number, b: number) => number} */ - function add2(a, b) { return a + b; } -->add2 : (a: number, b: number) => number -->a : number -->b : number -->a + b : number -->a : number -->b : number -+>add2 : (a: any, b: any) => any -+>a : any -+>b : any -+>a + b : any -+>a : any -+>b : any - +@@= skipped -19, +19 lines =@@ // TODO: Should be an error since signature doesn't match. /** @type {(a: number, b: number, c: number) => number} */ function add3(a, b) { return a + b; } ->add3 : (a: number, b: number, c: number) => number -->a : number -->b : number -->a + b : number -->a : number -->b : number -+>add3 : (a: any, b: any) => any -+>a : any -+>b : any -+>a + b : any -+>a : any -+>b : any - - // Confirm initializers are compatible. - // They can't have more parameters than the type/context. ++>add3 : (a: number, b: number) => number + >a : number + >b : number + >a + b : number +@@= skipped -12, +12 lines =@@ /** @type {() => void} */ function funcWithMoreParameters(more) {} // error @@ -55,14 +27,12 @@ >more : any /** @type {() => void} */ -@@= skipped -47, +47 lines =@@ - >more : any - - ({ -->({ /** @type {() => void} */ methodWithMoreParameters(more) {}, // error}) : { methodWithMoreParameters(): void; } -->{ /** @type {() => void} */ methodWithMoreParameters(more) {}, // error} : { methodWithMoreParameters(): void; } -+>({ /** @type {() => void} */ methodWithMoreParameters(more) {}, // error}) : { methodWithMoreParameters(more: any): void; } -+>{ /** @type {() => void} */ methodWithMoreParameters(more) {}, // error} : { methodWithMoreParameters(more: any): void; } +@@= skipped -21, +21 lines =@@ /** @type {() => void} */ - methodWithMoreParameters(more) {}, // error \ No newline at end of file + methodWithMoreParameters(more) {}, // error +->methodWithMoreParameters : (more: any) => void ++>methodWithMoreParameters : () => void + >more : any + + }); \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag7.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag7.types.diff index 6da6fb8b23..bb0fb6f28f 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag7.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag7.types.diff @@ -1,15 +1,6 @@ --- old.checkJsdocTypeTag7.types +++ new.checkJsdocTypeTag7.types -@@= skipped -9, +9 lines =@@ - - /** @type {Foo} */ - foo(a, b) {} -->foo : (a: string, b: number) => void -->a : string -->b : number -+>foo : (a: any, b: any) => void -+>a : any -+>b : any +@@= skipped -15, +15 lines =@@ /** @type {(optional?) => void} */ methodWithOptionalParameters() {} diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTagOnObjectProperty1.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTagOnObjectProperty1.errors.txt.diff index 695c813a6d..4df7dcb221 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTagOnObjectProperty1.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTagOnObjectProperty1.errors.txt.diff @@ -2,10 +2,12 @@ +++ new.checkJsdocTypeTagOnObjectProperty1.errors.txt @@= skipped -0, +0 lines =@@ - ++0.js(8,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'? ++0.js(8,14): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. +0.js(16,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'? + + -+==== 0.js (1 errors) ==== ++==== 0.js (3 errors) ==== + // @ts-check + var lol = "hello Lol" + const obj = { @@ -14,6 +16,11 @@ + /** @type {string|undefined} */ + bar: "42", + /** @type {function(number): number} */ ++ ~~~~~~~~ ++!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'? ++!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here. ++ ~~~~~~~~ ++!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. + method1(n1) { + return n1 + 42; + }, diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTagOnObjectProperty2.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTagOnObjectProperty2.errors.txt.diff index b398e62b86..e6472b5cf2 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTagOnObjectProperty2.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTagOnObjectProperty2.errors.txt.diff @@ -12,16 +12,25 @@ - - -==== 0.js (8 errors) ==== ++0.js(6,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'? ++0.js(6,14): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. +0.js(10,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'? +0.js(12,14): error TS2552: Cannot find name 'function'. Did you mean 'Function'? + + -+==== 0.js (3 errors) ==== ++==== 0.js (5 errors) ==== // @ts-check var lol; const obj = { -@@= skipped -18, +13 lines =@@ +@@= skipped -16, +13 lines =@@ + ~~~~~~~ + !!! error TS2322: Type 'number' is not assignable to type 'string'. /** @type {function(number): number} */ ++ ~~~~~~~~ ++!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'? ++!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here. ++ ~~~~~~~~ ++!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. method1(n1) { return "42"; - ~~~~~~ diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/errorOnFunctionReturnType.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/errorOnFunctionReturnType.errors.txt.diff index edfe5ae50a..c5174665c1 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/errorOnFunctionReturnType.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/errorOnFunctionReturnType.errors.txt.diff @@ -3,30 +3,36 @@ @@= skipped -0, +0 lines =@@ -foo.js(7,10): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. -foo.js(11,12): error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. --foo.js(13,5): error TS2322: Type 'string' is not assignable to type 'number'. ++foo.js(6,12): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. + foo.js(13,5): error TS2322: Type 'string' is not assignable to type 'number'. -foo.js(16,60): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. -foo.js(21,20): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. -foo.js(31,10): error TS2534: A function returning 'never' cannot have a reachable end point. -foo.js(35,12): error TS1065: The return type of an async function or method must be the global Promise type. --foo.js(37,5): error TS2322: Type '"asd"' is not assignable to type 'never'. ++foo.js(16,31): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. ++foo.js(21,5): error TS2322: Type '() => void' is not assignable to type 'FunctionReturningPromise'. ++ Type 'void' is not assignable to type 'Promise'. ++foo.js(30,12): error TS2534: A function returning 'never' cannot have a reachable end point. + foo.js(37,5): error TS2322: Type '"asd"' is not assignable to type 'never'. -foo.js(40,56): error TS2534: A function returning 'never' cannot have a reachable end point. -foo.js(45,18): error TS2534: A function returning 'never' cannot have a reachable end point. - - -==== foo.js (10 errors) ==== -+foo.js(21,5): error TS2322: Type '() => void' is not assignable to type 'FunctionReturningPromise'. -+ Type 'void' is not assignable to type 'Promise'. ++foo.js(40,29): error TS2534: A function returning 'never' cannot have a reachable end point. +foo.js(45,5): error TS2322: Type '() => void' is not assignable to type 'FunctionReturningNever'. + Type 'void' is not assignable to type 'never'. + + -+==== foo.js (2 errors) ==== ++==== foo.js (8 errors) ==== /** * @callback FunctionReturningPromise * @returns {Promise} -@@= skipped -17, +11 lines =@@ + */ /** @type {FunctionReturningPromise} */ ++ ~~~~~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. function testPromise1() { - ~~~~~~~~~~~~ -!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. @@ -38,13 +44,14 @@ -!!! error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. async function testPromise2() { return "asd"; -- ~~~~~~ --!!! error TS2322: Type 'string' is not assignable to type 'number'. + ~~~~~~ +@@= skipped -32, +30 lines =@@ } var testPromise3 = /** @type {FunctionReturningPromise} */ function() { - ~~~~~~~~ --!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. ++ ~~~~~~~~~~~~~~~~~~~~~~~~ + !!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. console.log("test") } @@ -58,28 +65,36 @@ console.log("test") } -@@= skipped -34, +27 lines =@@ +@@= skipped -18, +19 lines =@@ + */ /** @type {FunctionReturningNever} */ - function testNever1() { +- function testNever1() { - ~~~~~~~~~~ -!!! error TS2534: A function returning 'never' cannot have a reachable end point. - - } - - /** @type {FunctionReturningNever} */ -- ~~~~~~~~~~~~~~~~~~~~~~ +- +- } +- +- /** @type {FunctionReturningNever} */ + ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1065: The return type of an async function or method must be the global Promise type. -!!! related TS1055 foo.js:27:14: Type 'never' is not a valid async function return type in ES5 because it does not refer to a Promise-compatible constructor value. ++!!! error TS2534: A function returning 'never' cannot have a reachable end point. ++ function testNever1() { ++ ++ } ++ ++ /** @type {FunctionReturningNever} */ async function testNever2() { return "asd"; -- ~~~~~~ --!!! error TS2322: Type '"asd"' is not assignable to type 'never'. + ~~~~~~ +@@= skipped -17, +14 lines =@@ } var testNever3 = /** @type {FunctionReturningNever} */ function() { - ~~~~~~~~ --!!! error TS2534: A function returning 'never' cannot have a reachable end point. ++ ~~~~~~~~~~~~~~~~~~~~~~ + !!! error TS2534: A function returning 'never' cannot have a reachable end point. console.log("test") } diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/errorOnFunctionReturnType.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/errorOnFunctionReturnType.types.diff index eb08033690..e2e0dfd39c 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/errorOnFunctionReturnType.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/errorOnFunctionReturnType.types.diff @@ -1,34 +1,15 @@ --- old.errorOnFunctionReturnType.types +++ new.errorOnFunctionReturnType.types -@@= skipped -7, +7 lines =@@ - - /** @type {FunctionReturningPromise} */ - function testPromise1() { -->testPromise1 : () => Promise -+>testPromise1 : () => void - - console.log("Nope"); - >console.log("Nope") : void -@@= skipped -12, +12 lines =@@ - - /** @type {FunctionReturningPromise} */ - async function testPromise2() { -->testPromise2 : () => Promise -+>testPromise2 : () => Promise - - return "asd"; - >"asd" : "asd" +@@= skipped -26, +26 lines =@@ } var testPromise3 = /** @type {FunctionReturningPromise} */ function() { ->testPromise3 : FunctionReturningPromise -->function() { console.log("test")} : () => Promise -+>testPromise3 : () => void -+>function() { console.log("test")} : () => void ++>testPromise3 : () => Promise + >function() { console.log("test")} : () => Promise console.log("test") - >console.log("test") : void -@@= skipped -21, +21 lines =@@ +@@= skipped -14, +14 lines =@@ /** @type {FunctionReturningPromise} */ var testPromise4 = function() { >testPromise4 : FunctionReturningPromise @@ -37,33 +18,16 @@ console.log("test") >console.log("test") : void -@@= skipped -17, +17 lines =@@ - - /** @type {FunctionReturningNever} */ - function testNever1() { -->testNever1 : () => never -+>testNever1 : () => void - - } - - /** @type {FunctionReturningNever} */ - async function testNever2() { -->testNever2 : () => never -+>testNever2 : () => Promise - - return "asd"; - >"asd" : "asd" +@@= skipped -30, +30 lines =@@ } var testNever3 = /** @type {FunctionReturningNever} */ function() { ->testNever3 : FunctionReturningNever -->function() { console.log("test")} : () => never -+>testNever3 : () => void -+>function() { console.log("test")} : () => void ++>testNever3 : () => never + >function() { console.log("test")} : () => never console.log("test") - >console.log("test") : void -@@= skipped -27, +27 lines =@@ +@@= skipped -14, +14 lines =@@ /** @type {FunctionReturningNever} */ var testNever4 = function() { >testNever4 : FunctionReturningNever diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunctionType.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunctionType.errors.txt.diff index 6b6ecc5911..899510ffa9 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunctionType.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunctionType.errors.txt.diff @@ -16,10 +16,9 @@ +functions.js(31,23): error TS7006: Parameter 'onetwo' implicitly has an 'any' type. +functions.js(49,13): error TS2749: 'D' refers to a value, but is being used as a type here. Did you mean 'typeof D'? +functions.js(51,26): error TS7006: Parameter 'dref' implicitly has an 'any' type. -+functions.js(72,14): error TS7019: Rest parameter 'args' implicitly has an 'any[]' type. + + -+==== functions.js (11 errors) ==== ++==== functions.js (10 errors) ==== /** * @param {function(this: string, number): number} c is just passing on through * @return {function(this: string, number): number} @@ -50,7 +49,7 @@ return c } -@@= skipped -32, +53 lines =@@ +@@= skipped -32, +52 lines =@@ z.length; /** @type {function ("a" | "b", 1 | 2): 3 | 4} */ @@ -88,13 +87,4 @@ -!!! related TS2728 functions.js:12:28: 'length' is declared here. // Repro from #39229 - -@@= skipped -11, +7 lines =@@ - * @type {(...args: [string, string] | [number, string, string]) => void} - */ - function foo(...args) { -+ ~~~~~~~ -+!!! error TS7019: Rest parameter 'args' implicitly has an 'any[]' type. - args; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunctionType.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunctionType.types.diff index 6c0fc15f2a..b2b6d3f645 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunctionType.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunctionType.types.diff @@ -209,32 +209,3 @@ +>E : (n: number) => void // Repro from #39229 - -@@= skipped -11, +11 lines =@@ - * @type {(...args: [string, string] | [number, string, string]) => void} - */ - function foo(...args) { -->foo : (...args: [string, string] | [number, string, string]) => void -->args : [string, string] | [number, string, string] -+>foo : (...args: any[]) => void -+>args : any[] - - args; -->args : [string, string] | [number, string, string] -+>args : any[] - } - - foo('abc', 'def'); - >foo('abc', 'def') : void -->foo : (...args: [string, string] | [number, string, string]) => void -+>foo : (...args: any[]) => void - >'abc' : "abc" - >'def' : "def" - - foo(42, 'abc', 'def'); - >foo(42, 'abc', 'def') : void -->foo : (...args: [string, string] | [number, string, string]) => void -+>foo : (...args: any[]) => void - >42 : 42 - >'abc' : "abc" - >'def' : "def" \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunction_missingReturn.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunction_missingReturn.errors.txt.diff index d6480c15d5..2a4513ad36 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunction_missingReturn.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocFunction_missingReturn.errors.txt.diff @@ -5,9 +5,18 @@ - - -==== /a.js (1 errors) ==== -- /** @type {function(): number} */ ++/a.js(1,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'? ++/a.js(1,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. ++ ++ ++==== /a.js (2 errors) ==== + /** @type {function(): number} */ - ~~~~~~ -!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. -- function f() {} -- -+ \ No newline at end of file ++ ~~~~~~~~ ++!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'? ++!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here. ++ ~~~~~~~~ ++!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. + function f() {} + \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.errors.txt.diff index 2475a703b5..9c0639589d 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.errors.txt.diff @@ -1,40 +1,27 @@ --- old.jsdocThisType.errors.txt +++ new.jsdocThisType.errors.txt -@@= skipped -0, +0 lines =@@ - /a.js(3,10): error TS2339: Property 'test' does not exist on type 'Foo'. --/a.js(8,10): error TS2339: Property 'test' does not exist on type 'Foo'. +@@= skipped -1, +1 lines =@@ + /a.js(8,10): error TS2339: Property 'test' does not exist on type 'Foo'. /a.js(13,10): error TS2339: Property 'test' does not exist on type 'Foo'. --/a.js(18,10): error TS2339: Property 'test' does not exist on type 'Foo'. + /a.js(18,10): error TS2339: Property 'test' does not exist on type 'Foo'. -/a.js(23,10): error TS2339: Property 'test' does not exist on type 'Foo'. -/a.js(28,10): error TS2339: Property 'test' does not exist on type 'Foo'. +/a.js(21,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'? ++/a.js(26,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'? ++/a.js(26,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. ==== /types.d.ts (0 errors) ==== -@@= skipped -12, +9 lines =@@ +@@= skipped -11, +12 lines =@@ export type M = (this: Foo) => void; -==== /a.js (6 errors) ==== -+==== /a.js (3 errors) ==== ++==== /a.js (7 errors) ==== /** @type {import('./types').M} */ export const f1 = function() { this.test(); -@@= skipped -11, +11 lines =@@ - /** @type {import('./types').M} */ - export function f2() { - this.test(); -- ~~~~ --!!! error TS2339: Property 'test' does not exist on type 'Foo'. - } - - /** @type {(this: import('./types').Foo) => void} */ -@@= skipped -14, +12 lines =@@ - /** @type {(this: import('./types').Foo) => void} */ - export function f4() { - this.test(); -- ~~~~ --!!! error TS2339: Property 'test' does not exist on type 'Foo'. +@@= skipped -30, +30 lines =@@ } /** @type {function(this: import('./types').Foo): void} */ @@ -48,6 +35,11 @@ } /** @type {function(this: import('./types').Foo): void} */ ++ ~~~~~~~~ ++!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'? ++!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here. ++ ~~~~~~~~ ++!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. export function f6() { this.test(); - ~~~~ diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.types.diff index fdb2517e54..d5b877b1ed 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.types.diff @@ -26,7 +26,7 @@ >this.test() : any >this.test : any ->this : import("/types").Foo -+>this : any ++>this : import("./types").Foo >test : any } @@ -48,7 +48,7 @@ >this.test() : any >this.test : any ->this : import("/types").Foo -+>this : any ++>this : import("./types").Foo >test : any } diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagParameterType.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagParameterType.errors.txt.diff index 0136365e68..d787b3e33e 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagParameterType.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagParameterType.errors.txt.diff @@ -2,15 +2,12 @@ +++ new.jsdocTypeTagParameterType.errors.txt @@= skipped -0, +0 lines =@@ -a.js(3,5): error TS2322: Type 'number' is not assignable to type 'string'. --a.js(7,5): error TS2322: Type 'number' is not assignable to type 'string'. -- -- --==== a.js (2 errors) ==== +a.js(1,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'? +a.js(2,12): error TS7006: Parameter 'value' implicitly has an 'any' type. -+a.js(6,12): error TS7006: Parameter 's' implicitly has an 'any' type. -+ -+ + a.js(7,5): error TS2322: Type 'number' is not assignable to type 'string'. + + +-==== a.js (2 errors) ==== +==== a.js (3 errors) ==== /** @type {function(string): void} */ + ~~~~~~~~ @@ -24,11 +21,4 @@ -!!! error TS2322: Type 'number' is not assignable to type 'string'. }; /** @type {(s: string) => void} */ - function g(s) { -+ ~ -+!!! error TS7006: Parameter 's' implicitly has an 'any' type. - s = 1 // Should error -- ~ --!!! error TS2322: Type 'number' is not assignable to type 'string'. - } - \ No newline at end of file + function g(s) { \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagParameterType.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagParameterType.types.diff index 279472df45..f3e04efd95 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagParameterType.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagParameterType.types.diff @@ -17,17 +17,4 @@ +>value : any >1 : 1 - }; - /** @type {(s: string) => void} */ - function g(s) { -->g : (s: string) => void -->s : string -+>g : (s: any) => void -+>s : any - - s = 1 // Should error - >s = 1 : 1 -->s : string -+>s : any - >1 : 1 - } + }; \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.errors.txt.diff index 28a1528267..75b452f94e 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.errors.txt.diff @@ -4,14 +4,12 @@ -a.js(11,1): error TS2554: Expected 1 arguments, but got 0. +a.js(1,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'? +a.js(2,12): error TS7006: Parameter 'value' implicitly has an 'any' type. -+a.js(5,12): error TS7006: Parameter 's' implicitly has an 'any' type. -+a.js(8,12): error TS7006: Parameter 's' implicitly has an 'any' type. a.js(12,1): error TS2554: Expected 1 arguments, but got 0. a.js(13,1): error TS2554: Expected 1 arguments, but got 0. -==== a.js (3 errors) ==== -+==== a.js (6 errors) ==== ++==== a.js (4 errors) ==== /** @type {function(string): void} */ + ~~~~~~~~ +!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'? @@ -22,13 +20,7 @@ }; /** @type {(s: string) => void} */ function g(s) { -+ ~ -+!!! error TS7006: Parameter 's' implicitly has an 'any' type. - } - /** @type {{(s: string): void}} */ - function h(s) { -+ ~ -+!!! error TS7006: Parameter 's' implicitly has an 'any' type. +@@= skipped -14, +20 lines =@@ } f() // should error diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.types.diff index e74d7340e3..7aa8087ae6 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.types.diff @@ -13,18 +13,7 @@ }; /** @type {(s: string) => void} */ - function g(s) { -->g : (s: string) => void -->s : string -+>g : (s: any) => void -+>s : any - } - /** @type {{(s: string): void}} */ - function h(s) { -->h : (s: string) => void -->s : string -+>h : (s: any) => void -+>s : any +@@= skipped -17, +17 lines =@@ } f() // should error @@ -34,11 +23,4 @@ +>f : function g() // should error - >g() : void -->g : (s: string) => void -+>g : (s: any) => void - - h() - >h() : void -->h : (s: string) => void -+>h : (s: any) => void + >g() : void \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/returnTagTypeGuard.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/returnTagTypeGuard.types.diff index 732e4797fe..3c6c7b5213 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/returnTagTypeGuard.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/returnTagTypeGuard.types.diff @@ -8,28 +8,4 @@ +>foo : (val: number | boolean) => void >val : number | boolean - if (isBoolean(val)) { -@@= skipped -21, +21 lines =@@ - - /** @type {Cb} */ - function isNumber(x) { return typeof x === "number" } -->isNumber : (x: unknown) => x is number -->x : unknown -+>isNumber : (x: any) => x is number -+>x : any - >typeof x === "number" : boolean - >typeof x : "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined" -->x : unknown -+>x : any - >"number" : "number" - - /** @param {unknown} x */ -@@= skipped -14, +14 lines =@@ - - if (isNumber(x)) { - >isNumber(x) : boolean -->isNumber : (x: unknown) => x is number -+>isNumber : (x: any) => x is number - >x : unknown - - x * 2; \ No newline at end of file + if (isBoolean(val)) { \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/typeFromJSInitializer3.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/typeFromJSInitializer3.errors.txt.diff deleted file mode 100644 index 91c53d5780..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/typeFromJSInitializer3.errors.txt.diff +++ /dev/null @@ -1,25 +0,0 @@ ---- old.typeFromJSInitializer3.errors.txt -+++ new.typeFromJSInitializer3.errors.txt -@@= skipped -0, +0 lines =@@ -- -+a.js(2,10): error TS7010: 'f1', which lacks return-type annotation, implicitly has an 'any' return type. -+a.js(8,10): error TS7010: 'f2', which lacks return-type annotation, implicitly has an 'any' return type. -+ -+ -+==== a.js (2 errors) ==== -+ /** @type {() => undefined} */ -+ function f1() { -+ ~~ -+!!! error TS7010: 'f1', which lacks return-type annotation, implicitly has an 'any' return type. -+ return undefined; -+ } -+ const a = f1() -+ -+ /** @type {() => null} */ -+ function f2() { -+ ~~ -+!!! error TS7010: 'f2', which lacks return-type annotation, implicitly has an 'any' return type. -+ return null; -+ } -+ const b = f2() -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/typeFromJSInitializer3.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/typeFromJSInitializer3.types.diff deleted file mode 100644 index 8916e796c9..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/typeFromJSInitializer3.types.diff +++ /dev/null @@ -1,34 +0,0 @@ ---- old.typeFromJSInitializer3.types -+++ new.typeFromJSInitializer3.types -@@= skipped -2, +2 lines =@@ - === a.js === - /** @type {() => undefined} */ - function f1() { -->f1 : () => undefined -+>f1 : () => any - - return undefined; - >undefined : undefined - } - const a = f1() -->a : undefined -->f1() : undefined -->f1 : () => undefined -+>a : any -+>f1() : any -+>f1 : () => any - - /** @type {() => null} */ - function f2() { -->f2 : () => null -+>f2 : () => any - - return null; - } - const b = f2() -->b : null -->f2() : null -->f2 : () => null -+>b : any -+>f2() : any -+>f2 : () => any diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagCircularReferenceOnConstructorFunction.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/typeTagCircularReferenceOnConstructorFunction.errors.txt.diff index 29f6516722..e30f3c7432 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagCircularReferenceOnConstructorFunction.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/typeTagCircularReferenceOnConstructorFunction.errors.txt.diff @@ -5,12 +5,18 @@ - - -==== bug27346.js (1 errors) ==== -- /** -- * @type {MyClass} -- ~~~~~~~ ++bug27346.js(2,11): error TS2749: 'MyClass' refers to a value, but is being used as a type here. Did you mean 'typeof MyClass'? ++bug27346.js(2,11): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. ++ ++ ++==== bug27346.js (2 errors) ==== + /** + * @type {MyClass} + ~~~~~~~ -!!! error TS8030: The type of a function declaration must match the function's signature. -- */ -- function MyClass() { } -- MyClass.prototype = {}; -- -+ \ No newline at end of file ++!!! error TS2749: 'MyClass' refers to a value, but is being used as a type here. Did you mean 'typeof MyClass'? ++ ~~~~~~~ ++!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments. + */ + function MyClass() { } + MyClass.prototype = {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagOnFunctionReferencesGeneric.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/typeTagOnFunctionReferencesGeneric.types.diff index ed888b6474..80d3d366a0 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagOnFunctionReferencesGeneric.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/typeTagOnFunctionReferencesGeneric.types.diff @@ -5,19 +5,16 @@ /**@type {IFn}*/ export function inJs(l) { ->inJs : (m: T) => T -->l : T -+>inJs : (l: any) => any -+>l : any ++>inJs : (l: T) => T + >l : T return l; -->l : T -+>l : any +@@= skipped -8, +8 lines =@@ } inJs(1); // lints error. Why? -->inJs(1) : 1 + >inJs(1) : 1 ->inJs : (m: T) => T -+>inJs(1) : any -+>inJs : (l: any) => any ++>inJs : (l: T) => T >1 : 1 /**@type {IFn}*/ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagWithGenericSignature.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/typeTagWithGenericSignature.errors.txt.diff deleted file mode 100644 index c4ed294238..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagWithGenericSignature.errors.txt.diff +++ /dev/null @@ -1,18 +0,0 @@ ---- old.typeTagWithGenericSignature.errors.txt -+++ new.typeTagWithGenericSignature.errors.txt -@@= skipped -0, +0 lines =@@ -- -+bug25618.js(2,16): error TS7006: Parameter 'param' implicitly has an 'any' type. -+ -+ -+==== bug25618.js (1 errors) ==== -+ /** @type {(param?: T) => T | undefined} */ -+ function typed(param) { -+ ~~~~~ -+!!! error TS7006: Parameter 'param' implicitly has an 'any' type. -+ return param; -+ } -+ -+ var n = typed(1); -+ -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagWithGenericSignature.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/typeTagWithGenericSignature.types.diff index 10edaf112e..d5a2254495 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagWithGenericSignature.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/typeTagWithGenericSignature.types.diff @@ -5,21 +5,15 @@ /** @type {(param?: T) => T | undefined} */ function typed(param) { ->typed : (param?: T) => T | undefined -->param : T | undefined -+>typed : (param: any) => any -+>param : any ++>typed : (param: T | undefined) => T | undefined + >param : T | undefined return param; -->param : T | undefined -+>param : any - } - +@@= skipped -10, +10 lines =@@ var n = typed(1); -->n : number | undefined -->typed(1) : 1 | undefined + >n : number | undefined + >typed(1) : 1 | undefined ->typed : (param?: T) => T | undefined -+>n : any -+>typed(1) : any -+>typed : (param: any) => any ++>typed : (param: T | undefined) => T | undefined >1 : 1 diff --git a/testdata/tests/cases/conformance/jsdoc/jsdocTypeParameterTagConflict.ts b/testdata/tests/cases/conformance/jsdoc/jsdocTypeParameterTagConflict.ts new file mode 100644 index 0000000000..ae4d73ea0e --- /dev/null +++ b/testdata/tests/cases/conformance/jsdoc/jsdocTypeParameterTagConflict.ts @@ -0,0 +1,26 @@ +// @allowJs: true +// @checkJs: true +// @declaration: true +// @emitDeclarationOnly: true + +// @Filename: /a.js +/** + * @type {(a: 1) => true} + * @param {2} a + */ +export function conflictingParam(a) { return true } + +/** + * @type {(b: 3) => true} + * @return {false} + */ +export function conflictingReturn(b) { return false } + + +/** + * @type {(c: 4) => true} + * @param {5} d + * @return {false} + */ +export function conflictingBoth(d) { return false } +