Class TypeDeclarationsIR

java.lang.Object
com.google.javascript.rhino.TypeDeclarationsIR

public final class TypeDeclarationsIR extends Object
An AST construction helper class for Node
  • Method Details

    • stringType

      public static Node stringType()
      Returns:
      a new node representing the string built-in type.
    • numberType

      public static Node numberType()
      Returns:
      a new node representing the number built-in type.
    • booleanType

      public static Node booleanType()
      Returns:
      a new node representing the boolean built-in type.
    • anyType

      public static Node anyType()
      Equivalent to the UNKNOWN type in Closure, expressed with {?}
      Returns:
      a new node representing any type, without type checking.
    • voidType

      public static Node voidType()
      Returns:
      a new node representing the Void type as defined by TypeScript.
    • undefinedType

      public static Node undefinedType()
      Returns:
      a new node representing the Undefined type as defined by TypeScript.
    • namedType

      public static Node namedType(String typeName)
      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

      public static Node namedType(Iterable<String> segments)
      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

      public static Node recordType(LinkedHashMap<String,Node> properties)
      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_TYPE
      requiredParams - 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

      public static Node parameterizedType(Node baseType, Iterable<Node> typeParameters)
      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

      public static Node arrayType(Node elementType)
      Represents an array type. In Closure, this is represented by a parameterized type of Array with elementType as the sole type parameter.

      Example

       ARRAY_TYPE
         elementType
       
    • unionType

      public static Node unionType(Iterable<Node> options)
      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

      public static Node unionType(Node... options)
    • optionalParameter

      public static Node optionalParameter(Node parameterType)
      Represents a function parameter that is optional. In closure syntax, this is function(?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