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§
- Abstract
Class Declaration - Abstract
Method Signature - Accessibility
Modifier - Adding
Type Annotation - Ambient
Declaration - Arguments
- Array
- Array
Pattern - Array
Type - Arrow
Function - AsExpression
- Asserts
- Asserts
Annotation - Assignment
Expression - Assignment
Pattern - Augmented
Assignment Expression - Await
Expression - Binary
Expression - Break
Statement - Call
Expression - Call
Signature - Catch
Clause - Class
- Class
Body - Class
Declaration - Class
Heritage - Class
Static Block - Comment
- Computed
Property Name - Conditional
Type - Constraint
- Construct
Signature - Constructor
Type - Continue
Statement - Debugger
Statement - Decorator
- Default
Type - DoStatement
- Else
Clause - Empty
Statement - Enum
Assignment - Enum
Body - Enum
Declaration - Escape
Sequence - Existential
Type - Export
Clause - Export
Specifier - Export
Statement - Expression
Statement - Extends
Clause - Extends
Type Clause - False
- Finally
Clause - Flow
Maybe Type - ForIn
Statement - ForStatement
- Formal
Parameters - Function
Declaration - Function
Expression - Function
Signature - Function
Type - Generator
Function - Generator
Function Declaration - Generic
Type - Hash
Bang Line - Html
Comment - Identifier
- IfStatement
- Implements
Clause - Import
- Import
Alias - Import
Attribute - Import
Clause - Import
Require Clause - Import
Specifier - Import
Statement - Index
Signature - Index
Type Query - Infer
Type - Instantiation
Expression - Interface
Body - Interface
Declaration - Internal
Module - Intersection
Type - Labeled
Statement - Lexical
Declaration - Literal
Type - Lookup
Type - Mapped
Type Clause - Member
Expression - Meta
Property - Method
Definition - Method
Signature - Module
- Named
Imports - Namespace
Export - Namespace
Import - Nested
Identifier - Nested
Type Identifier - NewExpression
- NonNull
Expression - Null
- Number
- Object
- Object
Assignment Pattern - Object
Pattern - Object
Type - Omitting
Type Annotation - Opting
Type Annotation - Optional
Chain - Optional
Parameter - Optional
Type - Override
Modifier - Pair
- Pair
Pattern - Parenthesized
Expression - Parenthesized
Type - Predefined
Type - Private
Property Identifier - Program
- Property
Identifier - Property
Signature - Public
Field Definition - Readonly
Type - Regex
- Regex
Flags - Regex
Pattern - Required
Parameter - Rest
Pattern - Rest
Type - Return
Statement - Satisfies
Expression - Sequence
Expression - Shorthand
Property Identifier - Shorthand
Property Identifier Pattern - Span
- Spread
Element - Statement
Block - Statement
Identifier - String
- String
Fragment - Subscript
Expression - Super
- Switch
Body - Switch
Case - Switch
Default - Switch
Statement - Template
Literal Type - Template
String - Template
Substitution - Template
Type - Ternary
Expression - This
- This
Type - Throw
Statement - True
- TryStatement
- Tuple
Type - Type
Alias Declaration - Type
Annotation - Type
Arguments - Type
Assertion - Type
Identifier - Type
Parameter - Type
Parameters - Type
Predicate - Type
Predicate Annotation - Type
Query - Unary
Expression - Undefined
- Union
Type - Update
Expression - Variable
Declaration - Variable
Declarator - While
Statement - With
Statement - Yield
Expression
Enums§
- Abstract
Method Signature Children - Abstract
Method Signature Name - Abstract
Method Signature Return Type - Ambient
Declaration Children - AnyNode
- Arguments
Children - Array
Children - Array
Pattern Children - Arrow
Function Body - Arrow
Function Return Type - AsExpression
Children - Asserts
Children - Assignment
Expression Left - Augmented
Assignment Expression Left - Augmented
Assignment Expression Operator - Binary
Expression Left - Binary
Expression Operator - Call
Expression Arguments - Call
Expression Function - Call
Signature Return Type - Catch
Clause Parameter - Class
Body Children - Class
Heritage Children - Declaration
- Decorator
Children - Enum
Assignment Name - Enum
Body Name - Export
Specifier Alias - Export
Specifier Name - Export
Statement Children - Expression
- Expression
Statement Children - Extends
Type Clause Type - ForIn
Statement Kind - ForIn
Statement Left - ForIn
Statement Operator - ForIn
Statement Right - ForStatement
Condition - ForStatement
Increment - ForStatement
Initializer - Formal
Parameters Children - Function
Declaration Return Type - Function
Expression Return Type - Function
Signature Return Type - Function
Type Return Type - Generator
Function Declaration Return Type - Generator
Function Return Type - Generic
Type Name - Import
Alias Children - Import
Clause Children - Import
Specifier Name - Import
Statement Children - Index
Signature Sign - Index
Signature Type - Infer
Type Children - Instantiation
Expression Function - Interface
Body Children - Internal
Module Name - Lexical
Declaration Kind - Literal
Type Children - Member
Expression Object - Member
Expression Property - Method
Definition Children - Method
Definition Name - Method
Definition Return Type - Method
Signature Children - Method
Signature Name - Method
Signature Return Type - Module
Name - Namespace
Export Children - Nested
Identifier Object - Nested
Type Identifier Module - Object
Assignment Pattern Left - Object
Children - Object
Pattern Children - Object
Type Children - Optional
Parameter Children - Optional
Parameter Pattern - PairKey
- Pair
Pattern Key - Pair
Pattern Value - Parenthesized
Expression Children - Parse
Error - Pattern
- Primary
Expression - Primary
Type - Program
Children - Property
Signature Children - Property
Signature Name - Public
Field Definition Children - Public
Field Definition Name - Required
Parameter Children - Required
Parameter Name - Required
Parameter Pattern - Rest
Pattern Children - Return
Statement Children - Satisfies
Expression Children - Statement
- String
Children - Subscript
Expression Index - Switch
Body Children - Switch
Case Value - Template
Literal Type Children - Template
String Children - Template
Substitution Children - Template
Type Children - Throw
Statement Children - Tuple
Type Children - Type
- Type
Assertion Children - Type
Predicate Name - Type
Query Children - Unary
Expression Argument - Unary
Expression Operator - Update
Expression Operator - Variable
Declarator Name