Package com.google.javascript.rhino
Class TypeDeclarationsIR
java.lang.Object
com.google.javascript.rhino.TypeDeclarationsIR
An AST construction helper class for Node
-
Method Summary
Modifier and TypeMethodDescriptionstatic NodeanyType()Equivalent to the UNKNOWN type in Closure, expressed with{?}static NodeRepresents an array type.static Nodestatic NodefunctionType(Node returnType, LinkedHashMap<String, Node> requiredParams, LinkedHashMap<String, Node> optionalParams, String restName, Node restType) Represents a function type.static NodeProduces a tree structure similar to the Rhino AST of a qualified name expression, under a top-level NAMED_TYPE node.static NodeSplits a '.' separated qualified name into a tree of type segments.static Nodestatic NodeoptionalParameter(Node parameterType) Represents a function parameter that is optional.static NodeparameterizedType(Node baseType, Iterable<Node> typeParameters) Represents a parameterized, or generic, type.static NoderecordType(LinkedHashMap<String, Node> properties) Represents a structural type.static Nodestatic Nodestatic Nodestatic NodeRepresents a union type, which can be one of the given types.static NodevoidType()
-
Method Details
-
stringType
- Returns:
- a new node representing the string built-in type.
-
numberType
- Returns:
- a new node representing the number built-in type.
-
booleanType
- Returns:
- a new node representing the boolean built-in type.
-
anyType
Equivalent to the UNKNOWN type in Closure, expressed with{?}- Returns:
- a new node representing any type, without type checking.
-
voidType
- Returns:
- a new node representing the Void type as defined by TypeScript.
-
undefinedType
- Returns:
- a new node representing the Undefined type as defined by TypeScript.
-
namedType
Splits a '.' separated qualified name into a tree of type segments.- Parameters:
typeName- a qualified name such as "goog.ui.Window"- Returns:
- a new node representing the type
- See Also:
-
namedType
Produces a tree structure similar to the Rhino AST of a qualified name expression, under a top-level NAMED_TYPE node.Example:
NAMED_TYPE NAME goog STRING ui STRING Window -
recordType
Represents a structural type. Closure calls this a Record Type and accepts the syntax{myNum: number, myObject}Example:
RECORD_TYPE STRING_KEY myNum NUMBER_TYPE STRING_KEY myObject- Parameters:
properties- a map from property name to property type- Returns:
- a new node representing the record type
-
functionType
public static Node functionType(Node returnType, LinkedHashMap<String, Node> requiredParams, LinkedHashMap<String, Node> optionalParams, String restName, Node restType) Represents a function type. Closure has syntax like{function(string, boolean):number}Closure doesn't include parameter names. If the parameter types are unnamed, arbitrary names can be substituted, eg. p1, p2, etc.Example:
FUNCTION_TYPE NUMBER_TYPE STRING_KEY p1 [declared_type_expr: STRING_TYPE] STRING_KEY p2 [declared_type_expr: BOOLEAN_TYPE]
- Parameters:
returnType- the type returned by the function, possibly ANY_TYPErequiredParams- the names and types of the required parameters.optionalParams- the names and types of the optional parameters.restName- the name of the rest parameter, if any.restType- the type of the rest parameter, if any.
-
parameterizedType
Represents a parameterized, or generic, type. Closure calls this a Type Application and accepts syntax like{Object.<string, number>}Example:
PARAMETERIZED_TYPE NAMED_TYPE NAME Object STRING_TYPE NUMBER_TYPE -
arrayType
Represents an array type. In Closure, this is represented by aparameterized typeofArraywithelementTypeas the sole type parameter.Example
ARRAY_TYPE elementType
-
unionType
Represents a union type, which can be one of the given types. Closure accepts syntax like{(number|boolean)}Example:
UNION_TYPE NUMBER_TYPE BOOLEAN_TYPE
- Parameters:
options- the types which are accepted- Returns:
- a new node representing the union type
-
unionType
-
optionalParameter
Represents a function parameter that is optional. In closure syntax, this isfunction(?string=, number=)In TypeScript syntax, it is(firstName: string, lastName?: string)=>string- Parameters:
parameterType- the type of the parameter- Returns:
- a new node representing the function parameter type
-