pub enum TypeInfo {
/// A shorthand type annotating the structure of an array: { number }
Array {
/// The braces (`{}`) containing the type info.
braces: ContainedSpan,
/// The access modifier of the array, `read` in `{ read number }`.
access: Option<TokenReference>,
/// The type info for the values in the Array
type_info: Box<TypeInfo>,
},
/// A standalone type, such as `string` or `Foo`.
Basic(TokenReference),
/// A singleton string type, such as `"hello"`
String(TokenReference),
/// A singleton boolean type, such as `true`
Boolean(TokenReference),
/// A callback type, such as `(string, number) => boolean`.
Callback {
/// Optional generics provided for the arguments, such as in `<T>(T) -> string`
generics: Option<GenericDeclaration>,
/// The parentheses for the arguments.
parentheses: ContainedSpan,
/// The argument types: `(string, number)`.
arguments: Punctuated<TypeArgument>,
/// The "thin arrow" (`->`) in between the arguments and the return type.
arrow: TokenReference,
/// The return type: `boolean`.
return_type: Box<TypeInfo>,
},
/// A type using generics, such as `map<number, string>`.
Generic {
/// The type that has generics: `map`.
base: TokenReference,
/// The arrows (`<>`) containing the type parameters.
arrows: ContainedSpan,
/// The type parameters: `number, string`.
generics: Punctuated<TypeInfo>,
},
/// A generic pack: `T...`.
/// Note, these are only available as return types, when annotating a vararg (`...`) in a function parameter, or as a generic type argument.
GenericPack {
/// The name of the type that is generic: `T`.
name: TokenReference,
/// The ellipsis: `...`.
ellipsis: TokenReference,
},
/// An intersection type, such as `string & number`.
Intersection(TypeIntersection),
/// A type coming from a module, such as `module.Foo`
Module {
/// The module the type is coming from: `module`.
module: TokenReference,
/// The punctuation (`.`) to index the module.
punctuation: TokenReference,
/// The indexed type info: `Foo`.
type_info: Box<IndexedTypeInfo>,
},
/// An optional type, such as `string?`.
Optional {
/// The type that is optional: `string`.
base: Box<TypeInfo>,
/// The question mark: `?`.
question_mark: TokenReference,
},
/// A type annotating the structure of a table: { foo: number, bar: string }
Table {
/// The braces (`{}`) containing the fields.
braces: ContainedSpan,
/// The fields: `foo: number, bar: string`.
fields: Punctuated<TypeField>,
},
/// A type in the form of `typeof(foo)`.
Typeof {
/// The token `typeof`.
typeof_token: TokenReference,
/// The parentheses used to contain the expression.
parentheses: ContainedSpan,
/// The inner expression: `foo`.
inner: Box<Expression>,
},
/// A tuple expression: `(string, number)`.
Tuple {
/// The parentheses used to contain the types
parentheses: ContainedSpan,
/// The types: `(string, number)`.
types: Punctuated<TypeInfo>,
},
/// A union type, such as `string | number`.
Union(TypeUnion),
/// A variadic type: `...number`.
Variadic {
/// The ellipsis: `...`.
ellipsis: TokenReference,
/// The type that is variadic: `number`.
type_info: Box<TypeInfo>,
},
/// A variadic type pack: `...T` in `Function<...T>`
VariadicPack {
/// The ellipsis: `...`
ellipsis: TokenReference,
/// The name of the type that is variadic: `T`
name: TokenReference,
},
}