Skip to content

Add basic jsdoc tag types #610

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
10c944c
First example of JS tag emitting types
sandersn Mar 6, 2025
d601063
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Mar 10, 2025
12dc74c
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Mar 10, 2025
eac0860
couple of small bug fixes/refactors
sandersn Mar 10, 2025
fce99be
Add basic uses of type and return tags
sandersn Mar 10, 2025
34666c3
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Mar 12, 2025
b15e970
Basic param support
sandersn Mar 12, 2025
551f4a4
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Mar 13, 2025
b6e920b
Completely unfinished typedef, need to push to sync to laptop
sandersn Mar 13, 2025
24efd00
finish adding @typedef
sandersn Mar 14, 2025
6e1b734
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Mar 14, 2025
d8d091f
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Mar 14, 2025
355a339
Remove JSTypeExpression wrapper, use Clone instead
sandersn Mar 14, 2025
5184fda
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Mar 17, 2025
4d420bc
Various fixes+ features
sandersn Mar 19, 2025
449315c
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Mar 19, 2025
20a6f6a
Add some tags, accept baselines
sandersn Mar 20, 2025
85a68a1
Add Host pointer to JSDocTypeExpression,fix name resolution
sandersn Mar 21, 2025
a74d9a8
support variabledeclaration as well
sandersn Mar 21, 2025
c0056b3
undo stray merge change
sandersn Mar 24, 2025
4d51c72
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Mar 24, 2025
f13059f
cosmetic cleanup
sandersn Mar 24, 2025
49fb006
undo bad typedef parsing simplification
sandersn Mar 24, 2025
f2852a8
remove unused JS checks in checker
sandersn Mar 24, 2025
e2c807e
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Mar 24, 2025
0fb08ce
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Mar 26, 2025
d448d64
remove JSTypeAliasDeclaration type, keep kind
sandersn Mar 26, 2025
fc6199b
remove another jsdoc todo
sandersn Mar 26, 2025
6146316
fix formatting
sandersn Mar 26, 2025
00e3d76
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Apr 1, 2025
9225da2
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Apr 1, 2025
f39861f
delete unused baselines
sandersn Apr 1, 2025
8c3e3ea
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Apr 3, 2025
bac9152
Merge branch 'add-basic-jsdoc-tag-types' of github.com:sandersn/types…
sandersn Apr 3, 2025
13ec1c3
Improve locations of reparsed nodes
sandersn Apr 3, 2025
8e71486
remove now-unneeded check in rangeOfTypeParameters
sandersn Apr 3, 2025
c7ae384
hereby format
sandersn Apr 3, 2025
6ba9c18
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Apr 7, 2025
7af2df5
update tests after merge
sandersn Apr 7, 2025
57badae
re-delete unused baselines
sandersn Apr 7, 2025
807d725
skip baselining all reparsed nodes except `as`
sandersn Apr 8, 2025
983f3b7
Merge branch 'main' into add-basic-jsdoc-tag-types
sandersn Apr 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
100 changes: 100 additions & 0 deletions internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ func (n *Node) TypeParameterList() *NodeList {
return n.AsInterfaceDeclaration().TypeParameters
case KindTypeAliasDeclaration:
return n.AsTypeAliasDeclaration().TypeParameters
case KindJSTypeAliasDeclaration:
return n.AsJSTypeAliasDeclaration().TypeParameters
default:
funcLike := n.FunctionLikeData()
if funcLike != nil {
Expand Down Expand Up @@ -479,6 +481,8 @@ func (n *Node) Type() *Node {
return n.AsSatisfiesExpression().Type
case KindTypeAliasDeclaration:
return n.AsTypeAliasDeclaration().Type
case KindJSTypeAliasDeclaration:
return n.AsJSTypeAliasDeclaration().Type
case KindNamedTupleMember:
return n.AsNamedTupleMember().Type
case KindOptionalType:
Expand All @@ -489,6 +493,8 @@ func (n *Node) Type() *Node {
return n.AsTemplateLiteralTypeSpan().Type
case KindJSDocTypeExpression:
return n.AsJSDocTypeExpression().Type
case KindJSTypeExpression:
return n.AsJSTypeExpression().Type
case KindJSDocNullableType:
return n.AsJSDocNullableType().Type
case KindJSDocNonNullableType:
Expand Down Expand Up @@ -1054,6 +1060,10 @@ func (n *Node) AsTypeAliasDeclaration() *TypeAliasDeclaration {
return n.data.(*TypeAliasDeclaration)
}

func (n *Node) AsJSTypeAliasDeclaration() *JSTypeAliasDeclaration {
return n.data.(*JSTypeAliasDeclaration)
}

func (n *Node) AsJsxAttribute() *JsxAttribute {
return n.data.(*JsxAttribute)
}
Expand Down Expand Up @@ -1358,6 +1368,10 @@ func (n *Node) AsJSDocTypeTag() *JSDocTypeTag {
return n.data.(*JSDocTypeTag)
}

func (n *Node) AsJSTypeExpression() *JSTypeExpression {
return n.data.(*JSTypeExpression)
}

func (n *Node) AsJSDocUnknownTag() *JSDocUnknownTag {
return n.data.(*JSDocUnknownTag)
}
Expand Down Expand Up @@ -3032,6 +3046,7 @@ type ClassLikeBase struct {
DeclarationBase
ExportableBase
ModifiersBase
LocalsContainerBase
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike type, @typedef is allowed as a local inside classes.

I haven't checked to see how common this is so I added support for now as a way of fixing a nil panic. But I will remove it if it's not common.

name *IdentifierNode // IdentifierNode
TypeParameters *NodeList // NodeList[*TypeParameterDeclarationNode]. Optional
HeritageClauses *NodeList // NodeList[*HeritageClauseNode]. Optional
Expand Down Expand Up @@ -3268,6 +3283,55 @@ func IsTypeAliasDeclaration(node *Node) bool {
return node.Kind == KindTypeAliasDeclaration
}

func IsEitherTypeAliasDeclaration(node *Node) bool {
return node.Kind == KindTypeAliasDeclaration || node.Kind == KindJSTypeAliasDeclaration
}

type JSTypeAliasDeclaration struct {
StatementBase
DeclarationBase
ExportableBase
ModifiersBase
LocalsContainerBase
name *IdentifierNode // IdentifierNode
TypeParameters *NodeList // NodeList[*TypeParameterDeclarationNode]. Optional
Type *TypeNode // TypeNode
}

func (f *NodeFactory) NewJSTypeAliasDeclaration(modifiers *ModifierList, name *IdentifierNode, typeParameters *NodeList, typeNode *TypeNode) *Node {
data := &JSTypeAliasDeclaration{}
data.modifiers = modifiers
data.name = name
data.TypeParameters = typeParameters
data.Type = typeNode
return newNode(KindJSTypeAliasDeclaration, data, f.hooks)
}

func (f *NodeFactory) UpdateJSTypeAliasDeclaration(node *JSTypeAliasDeclaration, modifiers *ModifierList, name *IdentifierNode, typeParameters *TypeParameterList, typeNode *TypeNode) *Node {
if modifiers != node.modifiers || name != node.name || typeParameters != node.TypeParameters || typeNode != node.Type {
return updateNode(f.NewJSTypeAliasDeclaration(modifiers, name, typeParameters, typeNode), node.AsNode(), f.hooks)
}
return node.AsNode()
}

func (node *JSTypeAliasDeclaration) ForEachChild(v Visitor) bool {
return visitModifiers(v, node.modifiers) || visit(v, node.name) || visitNodeList(v, node.TypeParameters) || visit(v, node.Type)
}

func (node *JSTypeAliasDeclaration) VisitEachChild(v *NodeVisitor) *Node {
return v.Factory.UpdateJSTypeAliasDeclaration(node, v.visitModifiers(node.modifiers), v.visitNode(node.name), v.visitNodes(node.TypeParameters), v.visitNode(node.Type))
}

func (node *JSTypeAliasDeclaration) Clone(f *NodeFactory) *Node {
return cloneNode(f.NewJSTypeAliasDeclaration(node.Modifiers(), node.Name(), node.TypeParameters, node.Type), node.AsNode(), f.hooks)
}

func (node *JSTypeAliasDeclaration) Name() *DeclarationName { return node.name }

func IsJSTypeAliasDeclaration(node *Node) bool {
return node.Kind == KindJSTypeAliasDeclaration
}

// EnumMember

type EnumMember struct {
Expand Down Expand Up @@ -7784,6 +7848,42 @@ func (node *JSDocOptionalType) Clone(f *NodeFactory) *Node {
return cloneNode(f.NewJSDocOptionalType(node.Type), node.AsNode(), f.hooks)
}

// TODO: This name is WAAAAAAAAAAAAY too close to JSDocTypeExpression. Either rename it or remove it or use an existing node
// JSTypeExpression
type JSTypeExpression struct {
TypeNodeBase
Type *TypeNode
}

func (f *NodeFactory) NewJSTypeExpression(typeNode *TypeNode) *Node {
data := &JSTypeExpression{}
data.Type = typeNode
return newNode(KindJSTypeExpression, data, f.hooks)
}

func (f *NodeFactory) UpdateJSTypeExpression(node *JSTypeExpression, typeNode *TypeNode) *Node {
if typeNode != node.Type {
return updateNode(f.NewJSTypeExpression(typeNode), node.AsNode(), f.hooks)
}
return node.AsNode()
}

func (node *JSTypeExpression) ForEachChild(v Visitor) bool {
return visit(v, node.Type)
}

func (node *JSTypeExpression) VisitEachChild(v *NodeVisitor) *Node {
return v.Factory.UpdateJSTypeExpression(node, v.visitNode(node.Type))
}

func (node *JSTypeExpression) Clone(f *NodeFactory) *Node {
return updateNode(f.NewJSTypeExpression(node.Type), node.AsNode(), f.hooks)
}

func IsJSTypeExpression(node *Node) bool {
return node.Kind == KindJSTypeExpression
}

// JSDocTypeTag

type JSDocTypeTag struct {
Expand Down
3 changes: 3 additions & 0 deletions internal/ast/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ const (
KindJSDocImportTag
// Synthesized list
KindSyntaxList
// Synthesized JS nodes
KindJSTypeExpression
KindJSTypeAliasDeclaration
// Transformation nodes
KindNotEmittedStatement
KindPartiallyEmittedExpression
Expand Down
16 changes: 9 additions & 7 deletions internal/ast/kind_stringer_generated.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ func isDeclarationStatementKind(kind Kind) bool {
KindClassDeclaration,
KindInterfaceDeclaration,
KindTypeAliasDeclaration,
KindJSTypeAliasDeclaration,
KindEnumDeclaration,
KindModuleDeclaration,
KindImportDeclaration,
Expand Down Expand Up @@ -2013,6 +2014,7 @@ func GetMeaningFromDeclaration(node *Node) SemanticMeaning {
case KindTypeParameter,
KindInterfaceDeclaration,
KindTypeAliasDeclaration,
KindJSTypeAliasDeclaration,
KindTypeLiteral:
return SemanticMeaningType
case KindEnumMember, KindClassDeclaration:
Expand Down Expand Up @@ -2140,7 +2142,7 @@ func getModuleInstanceStateCached(node *Node, ancestors []*Node, visited map[Nod
func getModuleInstanceStateWorker(node *Node, ancestors []*Node, visited map[NodeId]ModuleInstanceState) ModuleInstanceState {
// A module is uninstantiated if it contains only
switch node.Kind {
case KindInterfaceDeclaration, KindTypeAliasDeclaration:
case KindInterfaceDeclaration, KindTypeAliasDeclaration, KindJSTypeAliasDeclaration:
return ModuleInstanceStateNonInstantiated
case KindEnumDeclaration:
if IsEnumConst(node) {
Expand Down
12 changes: 6 additions & 6 deletions internal/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (b *Binder) declareSymbolAndAddToSymbolTable(node *ast.Node, symbolFlags as
case ast.KindFunctionType, ast.KindConstructorType, ast.KindCallSignature, ast.KindConstructSignature, ast.KindJSDocSignature,
ast.KindIndexSignature, ast.KindMethodDeclaration, ast.KindMethodSignature, ast.KindConstructor, ast.KindGetAccessor,
ast.KindSetAccessor, ast.KindFunctionDeclaration, ast.KindFunctionExpression, ast.KindArrowFunction,
ast.KindClassStaticBlockDeclaration, ast.KindTypeAliasDeclaration, ast.KindMappedType:
ast.KindClassStaticBlockDeclaration, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindMappedType:
return b.declareSymbol(ast.GetLocals(b.container), nil /*parent*/, node, symbolFlags, symbolExcludes)
}
panic("Unhandled case in declareSymbolAndAddToSymbolTable")
Expand Down Expand Up @@ -670,7 +670,7 @@ func (b *Binder) bind(node *ast.Node) bool {
b.bindClassLikeDeclaration(node)
case ast.KindInterfaceDeclaration:
b.bindBlockScopedDeclaration(node, ast.SymbolFlagsInterface, ast.SymbolFlagsInterfaceExcludes)
case ast.KindTypeAliasDeclaration:
case ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration:
b.bindBlockScopedDeclaration(node, ast.SymbolFlagsTypeAlias, ast.SymbolFlagsTypeAliasExcludes)
case ast.KindEnumDeclaration:
b.bindEnumDeclaration(node)
Expand Down Expand Up @@ -1388,7 +1388,7 @@ func (b *Binder) bindContainer(node *ast.Node, containerFlags ContainerFlags) {
b.blockScopeContainer = node
if containerFlags&ContainerFlagsHasLocals != 0 {
// localsContainer := node
// localsContainer.LocalsContainerData().locals = make(SymbolTable)
// localsContainer.LocalsContainerData().locals = make(ast.SymbolTable)
b.addToContainerChain(node)
}
} else if containerFlags&ContainerFlagsIsBlockScopedContainer != 0 {
Expand Down Expand Up @@ -1690,7 +1690,7 @@ func (b *Binder) isExecutableStatement(s *ast.Node) bool {

func (b *Binder) isPurelyTypeDeclaration(s *ast.Node) bool {
switch s.Kind {
case ast.KindInterfaceDeclaration, ast.KindTypeAliasDeclaration:
case ast.KindInterfaceDeclaration, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration:
return true
case ast.KindModuleDeclaration:
return ast.GetModuleInstanceState(s) != ast.ModuleInstanceStateInstantiated
Expand Down Expand Up @@ -2487,7 +2487,7 @@ func GetContainerFlags(node *ast.Node) ContainerFlags {
return ContainerFlagsIsContainer
case ast.KindInterfaceDeclaration:
return ContainerFlagsIsContainer | ContainerFlagsIsInterface
case ast.KindModuleDeclaration, ast.KindTypeAliasDeclaration, ast.KindMappedType, ast.KindIndexSignature:
case ast.KindModuleDeclaration, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindMappedType, ast.KindIndexSignature:
return ContainerFlagsIsContainer | ContainerFlagsHasLocals
case ast.KindSourceFile:
return ContainerFlagsIsContainer | ContainerFlagsIsControlFlowContainer | ContainerFlagsHasLocals
Expand Down Expand Up @@ -2799,7 +2799,7 @@ func GetErrorRangeForNode(sourceFile *ast.SourceFile, node *ast.Node) core.TextR
// This list is a work in progress. Add missing node kinds to improve their error spans
case ast.KindVariableDeclaration, ast.KindBindingElement, ast.KindClassDeclaration, ast.KindClassExpression, ast.KindInterfaceDeclaration,
ast.KindModuleDeclaration, ast.KindEnumDeclaration, ast.KindEnumMember, ast.KindFunctionDeclaration, ast.KindFunctionExpression,
ast.KindMethodDeclaration, ast.KindGetAccessor, ast.KindSetAccessor, ast.KindTypeAliasDeclaration, ast.KindPropertyDeclaration,
ast.KindMethodDeclaration, ast.KindGetAccessor, ast.KindSetAccessor, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindPropertyDeclaration,
ast.KindPropertySignature, ast.KindNamespaceImport:
errorNode = ast.GetNameOfDeclaration(node)
case ast.KindArrowFunction:
Expand Down
2 changes: 1 addition & 1 deletion internal/binder/nameresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func isSelfReferenceLocation(node *ast.Node, lastLocation *ast.Node) bool {
case ast.KindParameter:
return lastLocation != nil && lastLocation == node.AsParameterDeclaration().Name()
case ast.KindFunctionDeclaration, ast.KindClassDeclaration, ast.KindInterfaceDeclaration, ast.KindEnumDeclaration,
ast.KindTypeAliasDeclaration, ast.KindModuleDeclaration: // For `namespace N { N; }`
ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindModuleDeclaration: // For `namespace N { N; }`
return true
}
return false
Expand Down
33 changes: 23 additions & 10 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2167,7 +2167,7 @@ func (c *Checker) checkSourceElementWorker(node *ast.Node) {
c.checkClassDeclaration(node)
case ast.KindInterfaceDeclaration:
c.checkInterfaceDeclaration(node)
case ast.KindTypeAliasDeclaration:
case ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration:
c.checkTypeAliasDeclaration(node)
case ast.KindEnumDeclaration:
c.checkEnumDeclaration(node)
Expand Down Expand Up @@ -2330,12 +2330,12 @@ func (c *Checker) checkTypeParameter(node *ast.Node) {
}

func (c *Checker) checkTypeParameterDeferred(node *ast.Node) {
if ast.IsInterfaceDeclaration(node.Parent) || ast.IsClassLike(node.Parent) || ast.IsTypeAliasDeclaration(node.Parent) {
if ast.IsInterfaceDeclaration(node.Parent) || ast.IsClassLike(node.Parent) || ast.IsTypeAliasDeclaration(node.Parent) || ast.IsJSTypeAliasDeclaration(node.Parent) {
typeParameter := c.getDeclaredTypeOfTypeParameter(c.getSymbolOfDeclaration(node))
modifiers := c.getTypeParameterModifiers(typeParameter) & (ast.ModifierFlagsIn | ast.ModifierFlagsOut)
if modifiers != 0 {
symbol := c.getSymbolOfDeclaration(node.Parent)
if ast.IsTypeAliasDeclaration(node.Parent) && c.getDeclaredTypeOfSymbol(symbol).objectFlags&(ObjectFlagsAnonymous|ObjectFlagsMapped) == 0 {
if (ast.IsTypeAliasDeclaration(node.Parent) || ast.IsJSTypeAliasDeclaration(node.Parent)) && c.getDeclaredTypeOfSymbol(symbol).objectFlags&(ObjectFlagsAnonymous|ObjectFlagsMapped) == 0 {
c.error(node, diagnostics.Variance_annotations_are_only_supported_in_type_aliases_for_object_function_constructor_and_mapped_types)
} else if modifiers == ast.ModifierFlagsIn || modifiers == ast.ModifierFlagsOut {
source := c.createMarkerType(symbol, typeParameter, core.IfElse(modifiers == ast.ModifierFlagsOut, c.markerSubTypeForCheck, c.markerSuperTypeForCheck))
Expand Down Expand Up @@ -6309,10 +6309,15 @@ func (c *Checker) checkTypeAliasDeclaration(node *ast.Node) {
c.checkTypeNameIsReserved(node.Name(), diagnostics.Type_alias_name_cannot_be_0)
c.checkExportsOnMergedDeclarations(node)

typeNode := node.AsTypeAliasDeclaration().Type
var typeNode *ast.Node
if node.Kind == ast.KindTypeAliasDeclaration {
typeNode = node.AsTypeAliasDeclaration().Type
} else if node.Kind == ast.KindJSTypeAliasDeclaration {
typeNode = node.AsJSTypeAliasDeclaration().Type
}
typeParameters := node.TypeParameters()
c.checkTypeParameters(typeParameters)
if typeNode.Kind == ast.KindIntrinsicKeyword {
if typeNode != nil && typeNode.Kind == ast.KindIntrinsicKeyword {
if !(len(typeParameters) == 0 && node.Name().Text() == "BuiltinIteratorReturn" ||
len(typeParameters) == 1 && intrinsicTypeKinds[node.Name().Text()] != IntrinsicTypeKindUnknown) {
c.error(typeNode, diagnostics.The_intrinsic_keyword_can_only_be_used_to_declare_compiler_provided_intrinsic_types)
Expand All @@ -6326,6 +6331,9 @@ func (c *Checker) checkTypeAliasDeclaration(node *ast.Node) {
func (c *Checker) checkTypeNameIsReserved(name *ast.Node, message *diagnostics.Message) {
// TS 1.0 spec (April 2014): 3.6.1
// The predefined type keywords are reserved and cannot be used as names of user defined types.
if name == nil { // TODO: Check when this happens
return
}
switch name.Text() {
case "any", "unknown", "never", "number", "bigint", "boolean", "string", "symbol", "void", "object", "undefined":
c.error(name, message, name.Text())
Expand Down Expand Up @@ -6397,7 +6405,7 @@ func (c *Checker) checkUnusedIdentifiers(potentiallyUnusedIdentifiers []*ast.Nod
}
c.checkUnusedTypeParameters(node)
case ast.KindMethodSignature, ast.KindCallSignature, ast.KindConstructSignature, ast.KindFunctionType, ast.KindConstructorType,
ast.KindTypeAliasDeclaration, ast.KindInterfaceDeclaration:
ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindInterfaceDeclaration:
c.checkUnusedTypeParameters(node)
case ast.KindInferType:
c.checkUnusedInferTypeParameter(node)
Expand Down Expand Up @@ -10430,7 +10438,7 @@ func (c *Checker) parameterInitializerContainsUndefined(declaration *ast.Node) b

func (c *Checker) isInAmbientOrTypeNode(node *ast.Node) bool {
return node.Flags&ast.NodeFlagsAmbient != 0 || ast.FindAncestor(node, func(n *ast.Node) bool {
return ast.IsInterfaceDeclaration(n) || ast.IsTypeAliasDeclaration(n) || ast.IsTypeLiteralNode(n)
return ast.IsInterfaceDeclaration(n) || ast.IsTypeAliasDeclaration(n) || ast.IsJSTypeAliasDeclaration(n) || ast.IsTypeLiteralNode(n)
}) != nil
}

Expand Down Expand Up @@ -20265,6 +20273,9 @@ func (c *Checker) couldContainTypeVariablesWorker(t *Type) bool {
func (c *Checker) isNonGenericTopLevelType(t *Type) bool {
if t.alias != nil && len(t.alias.typeArguments) == 0 {
declaration := ast.GetDeclarationOfKind(t.alias.symbol, ast.KindTypeAliasDeclaration)
if declaration == nil {
declaration = ast.GetDeclarationOfKind(t.alias.symbol, ast.KindJSTypeAliasDeclaration)
}
return declaration != nil && ast.FindAncestorOrQuit(declaration.Parent, func(n *ast.Node) ast.FindAncestorResult {
switch n.Kind {
case ast.KindSourceFile:
Expand Down Expand Up @@ -20922,6 +20933,8 @@ func (c *Checker) getTypeFromTypeNodeWorker(node *ast.Node) *Type {
return c.getTypeFromNamedTupleTypeNode(node)
case ast.KindParenthesizedType:
return c.getTypeFromTypeNode(node.AsParenthesizedTypeNode().Type)
case ast.KindJSTypeExpression:
return c.getTypeFromTypeNode(node.AsJSTypeExpression().Type)
case ast.KindRestType:
return c.getTypeFromRestTypeNode(node)
case ast.KindFunctionType, ast.KindConstructorType, ast.KindTypeLiteral:
Expand Down Expand Up @@ -21230,7 +21243,7 @@ func (c *Checker) isResolvedByTypeAlias(node *ast.Node) bool {
case ast.KindParenthesizedType, ast.KindNamedTupleMember, ast.KindTypeReference, ast.KindUnionType, ast.KindIntersectionType,
ast.KindIndexedAccessType, ast.KindConditionalType, ast.KindTypeOperator, ast.KindArrayType, ast.KindTupleType:
return c.isResolvedByTypeAlias(parent)
case ast.KindTypeAliasDeclaration:
case ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration:
return true
}
return false
Expand Down Expand Up @@ -21728,7 +21741,7 @@ func (c *Checker) getOuterTypeParameters(node *ast.Node, includeThisTypes bool)
switch kind {
case ast.KindClassDeclaration, ast.KindClassExpression, ast.KindInterfaceDeclaration, ast.KindCallSignature, ast.KindConstructSignature,
ast.KindMethodSignature, ast.KindFunctionType, ast.KindConstructorType, ast.KindFunctionDeclaration,
ast.KindMethodDeclaration, ast.KindFunctionExpression, ast.KindArrowFunction, ast.KindTypeAliasDeclaration, ast.KindMappedType,
ast.KindMethodDeclaration, ast.KindFunctionExpression, ast.KindArrowFunction, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindMappedType,
ast.KindConditionalType:
outerTypeParameters := c.getOuterTypeParameters(node, includeThisTypes)
if (kind == ast.KindFunctionExpression || kind == ast.KindArrowFunction || ast.IsObjectLiteralMethod(node)) && c.isContextSensitive(node) {
Expand Down Expand Up @@ -21807,7 +21820,7 @@ func (c *Checker) getDeclaredTypeOfTypeAlias(symbol *ast.Symbol) *Type {
if !c.pushTypeResolution(symbol, TypeSystemPropertyNameDeclaredType) {
return c.errorType
}
declaration := core.Find(symbol.Declarations, ast.IsTypeAliasDeclaration)
declaration := core.Find(symbol.Declarations, ast.IsEitherTypeAliasDeclaration)
typeNode := declaration.AsTypeAliasDeclaration().Type
t := c.getTypeFromTypeNode(typeNode)
if c.popTypeResolution() {
Expand Down
1 change: 1 addition & 0 deletions internal/checker/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2668,6 +2668,7 @@ func (c *Checker) markNodeAssignmentsWorker(node *ast.Node) bool {
return false
case ast.KindInterfaceDeclaration,
ast.KindTypeAliasDeclaration,
ast.KindJSTypeAliasDeclaration,
ast.KindEnumDeclaration:
return false
}
Expand Down
5 changes: 3 additions & 2 deletions internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (c *Checker) checkGrammarModifiers(node *ast.Node /*Union[HasModifiers, Has
return c.grammarErrorOnNode(modifier, diagnostics.X_0_modifier_must_precede_1_modifier, "export", "abstract")
} else if flags&ast.ModifierFlagsAsync != 0 {
return c.grammarErrorOnNode(modifier, diagnostics.X_0_modifier_must_precede_1_modifier, "export", "async")
} else if ast.IsClassLike(node.Parent) {
} else if ast.IsClassLike(node.Parent) && !ast.IsJSTypeAliasDeclaration(node) {
return c.grammarErrorOnNode(modifier, diagnostics.X_0_modifier_cannot_appear_on_class_elements_of_this_kind, "export")
} else if node.Kind == ast.KindParameter {
return c.grammarErrorOnNode(modifier, diagnostics.X_0_modifier_cannot_appear_on_a_parameter, "export")
Expand Down Expand Up @@ -604,7 +604,8 @@ func (c *Checker) findFirstIllegalModifier(node *ast.Node) *ast.Node {
ast.KindFunctionExpression,
ast.KindArrowFunction,
ast.KindParameter,
ast.KindTypeParameter:
ast.KindTypeParameter,
ast.KindJSTypeAliasDeclaration:
return nil
case ast.KindClassStaticBlockDeclaration,
ast.KindPropertyAssignment,
Expand Down
Loading
Loading