oak_typescript/ast/
type_node.rs1use crate::ast::{ClassMember, FunctionParam, LiteralType};
2use core::range::Range;
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone)]
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8pub enum TypeAnnotation {
9 Identifier(String),
10 Predefined(String), Literal(LiteralType),
12 Array(Box<TypeAnnotation>),
13 Tuple(Vec<TypeAnnotation>),
14 Union(Vec<TypeAnnotation>),
15 Intersection(Vec<TypeAnnotation>),
16 Reference { name: String, args: Vec<TypeAnnotation> },
17 Function { params: Vec<TypeParameter>, args: Vec<FunctionParam>, return_type: Box<TypeAnnotation> },
18 Object(Vec<ClassMember>),
19 Query(String), KeyOf(Box<TypeAnnotation>),
21 Conditional { check_type: Box<TypeAnnotation>, extends_type: Box<TypeAnnotation>, true_type: Box<TypeAnnotation>, false_type: Box<TypeAnnotation> },
22 Mapped { key_name: String, key_type: Box<TypeAnnotation>, value_type: Box<TypeAnnotation>, readonly: Option<bool>, optional: Option<bool> },
23 TemplateLiteral(Vec<TemplateElement>),
24 Infer(String),
25}
26
27#[derive(Debug, Clone)]
28#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
29pub struct TypeParameter {
30 pub name: String,
31 pub constraint: Option<TypeAnnotation>,
32 pub default: Option<TypeAnnotation>,
33 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
34 pub span: Range<usize>,
35}
36
37#[derive(Debug, Clone)]
38#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
39pub enum TemplateElement {
40 String(String),
41 Type(Box<TypeAnnotation>),
42}