Skip to main content

Crate treesitter_types_typescript

Crate treesitter_types_typescript 

Source
Expand description

Strongly-typed AST types for TypeScript, auto-generated from tree-sitter-typescript’s node-types.json.

This crate is generated by treesitter-types and is automatically kept up to date when a new version of the grammar crate is released.

These types have been tested by parsing the TypeScript source code.

See the Tree-sitter project for more information about the underlying parser framework.

§Example

use treesitter_types_typescript::*;

// A minimal TypeScript hello-world program.
let src = b"\
function greet(name: string): void {
    console.log(\"Hello, \" + name + \"!\");
}

greet(\"World\");
";

// Parse the source with tree-sitter and convert into typed AST.
let mut parser = tree_sitter::Parser::new();
parser
    .set_language(&tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into())
    .unwrap();
let tree = parser.parse(src, None).unwrap();
let program = Program::from_node(tree.root_node(), src).unwrap();

// The program has two top-level children.
assert_eq!(program.children.len(), 2);

// 1) The function declaration — `function greet(name: string): void { ... }`.
let ProgramChildren::Statement(stmt) = &program.children[0] else {
    panic!("expected a statement");
};
let Statement::Declaration(decl) = stmt.as_ref() else {
    panic!("expected a declaration");
};
let Declaration::FunctionDeclaration(func) = decl.as_ref() else {
    panic!("expected a function declaration");
};
assert_eq!(func.name.text(), "greet");
assert_eq!(func.parameters.children.len(), 1); // one parameter: `name: string`
assert!(func.return_type.is_some());            // has return type `: void`

// 2) The call expression — `greet("World");`.
let ProgramChildren::Statement(call_stmt) = &program.children[1] else {
    panic!("expected a statement");
};
let Statement::ExpressionStatement(expr) = call_stmt.as_ref() else {
    panic!("expected an expression statement");
};
assert_eq!(expr.span.start.row, 4);

Structs§

AbstractClassDeclaration
AbstractMethodSignature
AccessibilityModifier
AddingTypeAnnotation
AmbientDeclaration
Arguments
Array
ArrayPattern
ArrayType
ArrowFunction
AsExpression
Asserts
AssertsAnnotation
AssignmentExpression
AssignmentPattern
AugmentedAssignmentExpression
AwaitExpression
BinaryExpression
BreakStatement
CallExpression
CallSignature
CatchClause
Class
ClassBody
ClassDeclaration
ClassHeritage
ClassStaticBlock
Comment
ComputedPropertyName
ConditionalType
Constraint
ConstructSignature
ConstructorType
ContinueStatement
DebuggerStatement
Decorator
DefaultType
DoStatement
ElseClause
EmptyStatement
EnumAssignment
EnumBody
EnumDeclaration
EscapeSequence
ExistentialType
ExportClause
ExportSpecifier
ExportStatement
ExpressionStatement
ExtendsClause
ExtendsTypeClause
False
FinallyClause
FlowMaybeType
ForInStatement
ForStatement
FormalParameters
FunctionDeclaration
FunctionExpression
FunctionSignature
FunctionType
GeneratorFunction
GeneratorFunctionDeclaration
GenericType
HashBangLine
HtmlComment
Identifier
IfStatement
ImplementsClause
Import
ImportAlias
ImportAttribute
ImportClause
ImportRequireClause
ImportSpecifier
ImportStatement
IndexSignature
IndexTypeQuery
InferType
InstantiationExpression
InterfaceBody
InterfaceDeclaration
InternalModule
IntersectionType
LabeledStatement
LexicalDeclaration
LiteralType
LookupType
MappedTypeClause
MemberExpression
MetaProperty
MethodDefinition
MethodSignature
Module
NamedImports
NamespaceExport
NamespaceImport
NestedIdentifier
NestedTypeIdentifier
NewExpression
NonNullExpression
Null
Number
Object
ObjectAssignmentPattern
ObjectPattern
ObjectType
OmittingTypeAnnotation
OptingTypeAnnotation
OptionalChain
OptionalParameter
OptionalType
OverrideModifier
Pair
PairPattern
ParenthesizedExpression
ParenthesizedType
PredefinedType
PrivatePropertyIdentifier
Program
PropertyIdentifier
PropertySignature
PublicFieldDefinition
ReadonlyType
Regex
RegexFlags
RegexPattern
RequiredParameter
RestPattern
RestType
ReturnStatement
SatisfiesExpression
SequenceExpression
ShorthandPropertyIdentifier
ShorthandPropertyIdentifierPattern
Span
SpreadElement
StatementBlock
StatementIdentifier
String
StringFragment
SubscriptExpression
Super
SwitchBody
SwitchCase
SwitchDefault
SwitchStatement
TemplateLiteralType
TemplateString
TemplateSubstitution
TemplateType
TernaryExpression
This
ThisType
ThrowStatement
True
TryStatement
TupleType
TypeAliasDeclaration
TypeAnnotation
TypeArguments
TypeAssertion
TypeIdentifier
TypeParameter
TypeParameters
TypePredicate
TypePredicateAnnotation
TypeQuery
UnaryExpression
Undefined
UnionType
UpdateExpression
VariableDeclaration
VariableDeclarator
WhileStatement
WithStatement
YieldExpression

Enums§

AbstractMethodSignatureChildren
AbstractMethodSignatureName
AbstractMethodSignatureReturnType
AmbientDeclarationChildren
AnyNode
ArgumentsChildren
ArrayChildren
ArrayPatternChildren
ArrowFunctionBody
ArrowFunctionReturnType
AsExpressionChildren
AssertsChildren
AssignmentExpressionLeft
AugmentedAssignmentExpressionLeft
AugmentedAssignmentExpressionOperator
BinaryExpressionLeft
BinaryExpressionOperator
CallExpressionArguments
CallExpressionFunction
CallSignatureReturnType
CatchClauseParameter
ClassBodyChildren
ClassHeritageChildren
Declaration
DecoratorChildren
EnumAssignmentName
EnumBodyName
ExportSpecifierAlias
ExportSpecifierName
ExportStatementChildren
Expression
ExpressionStatementChildren
ExtendsTypeClauseType
ForInStatementKind
ForInStatementLeft
ForInStatementOperator
ForInStatementRight
ForStatementCondition
ForStatementIncrement
ForStatementInitializer
FormalParametersChildren
FunctionDeclarationReturnType
FunctionExpressionReturnType
FunctionSignatureReturnType
FunctionTypeReturnType
GeneratorFunctionDeclarationReturnType
GeneratorFunctionReturnType
GenericTypeName
ImportAliasChildren
ImportClauseChildren
ImportSpecifierName
ImportStatementChildren
IndexSignatureSign
IndexSignatureType
InferTypeChildren
InstantiationExpressionFunction
InterfaceBodyChildren
InternalModuleName
LexicalDeclarationKind
LiteralTypeChildren
MemberExpressionObject
MemberExpressionProperty
MethodDefinitionChildren
MethodDefinitionName
MethodDefinitionReturnType
MethodSignatureChildren
MethodSignatureName
MethodSignatureReturnType
ModuleName
NamespaceExportChildren
NestedIdentifierObject
NestedTypeIdentifierModule
ObjectAssignmentPatternLeft
ObjectChildren
ObjectPatternChildren
ObjectTypeChildren
OptionalParameterChildren
OptionalParameterPattern
PairKey
PairPatternKey
PairPatternValue
ParenthesizedExpressionChildren
ParseError
Pattern
PrimaryExpression
PrimaryType
ProgramChildren
PropertySignatureChildren
PropertySignatureName
PublicFieldDefinitionChildren
PublicFieldDefinitionName
RequiredParameterChildren
RequiredParameterName
RequiredParameterPattern
RestPatternChildren
ReturnStatementChildren
SatisfiesExpressionChildren
Statement
StringChildren
SubscriptExpressionIndex
SwitchBodyChildren
SwitchCaseValue
TemplateLiteralTypeChildren
TemplateStringChildren
TemplateSubstitutionChildren
TemplateTypeChildren
ThrowStatementChildren
TupleTypeChildren
Type
TypeAssertionChildren
TypePredicateName
TypeQueryChildren
UnaryExpressionArgument
UnaryExpressionOperator
UpdateExpressionOperator
VariableDeclaratorName

Traits§

FromNode
Every generated struct and enum implements this.
LeafNode
Implemented by every generated leaf type (identifiers, literals, etc.)
Spanned
Implemented by every generated type that has a source location.