@@ -686,6 +686,9 @@ class TypeExpr extends ExprOrType, @typeexpr {
686686 /** Holds if this is the `object` type. */
687687 predicate isObjectKeyword ( ) { none ( ) }
688688
689+ /** Holds if this is the `unknown` type. */
690+ predicate isUnknownKeyword ( ) { none ( ) }
691+
689692 /** Gets this type expression, with any surrounding parentheses removed. */
690693 override TypeExpr stripParens ( ) {
691694 result = this
@@ -725,6 +728,7 @@ private class KeywordTypeExpr extends @keywordtypeexpr, TypeExpr {
725728 override predicate isSymbol ( ) { getName ( ) = "symbol" }
726729 override predicate isUniqueSymbol ( ) { getName ( ) = "unique symbol" }
727730 override predicate isObjectKeyword ( ) { getName ( ) = "object" }
731+ override predicate isUnknownKeyword ( ) { getName ( ) = "unknown" }
728732}
729733
730734/**
@@ -1073,6 +1077,25 @@ class IsTypeExpr extends @istypeexpr, TypeExpr {
10731077 TypeExpr getPredicateType ( ) { result = this .getChildTypeExpr ( 1 ) }
10741078}
10751079
1080+ /**
1081+ * An optional type element in a tuple type, such as `number?` in `[string, number?]`.
1082+ */
1083+ class OptionalTypeExpr extends @optionaltypeexpr, TypeExpr {
1084+ /** Gets the type `T` in `T?` */
1085+ TypeExpr getElementType ( ) { result = getChildTypeExpr ( 0 ) }
1086+ }
1087+
1088+ /**
1089+ * A rest element in a tuple type, such as `...string[]` in `[number, ...string[]]`.
1090+ */
1091+ class RestTypeExpr extends @resttypeexpr, TypeExpr {
1092+ /** Gets the type `T[]` in `...T[]`, such as `string[]` in `[number, ...string[]]`. */
1093+ TypeExpr getArrayType ( ) { result = getChildTypeExpr ( 0 ) }
1094+
1095+ /** Gets the type `T` in `...T[]`, such as `string` in `[number, ...string[]]`. */
1096+ TypeExpr getElementType ( ) { result = getArrayType ( ) .( ArrayTypeExpr ) .getElementType ( ) }
1097+ }
1098+
10761099/**
10771100 * A possibly qualified name that refers to a variable from inside a type.
10781101 *
@@ -2143,7 +2166,7 @@ class TupleType extends ArrayType, @tupletype {
21432166 }
21442167
21452168 /**
2146- * Gets the number of elements in this tuple type.
2169+ * Gets the number of elements in this tuple type, including optional elements and the rest element .
21472170 */
21482171 int getNumElementType ( ) {
21492172 result = count ( int i | exists ( getElementType ( i ) ) )
@@ -2158,13 +2181,43 @@ class TupleType extends ArrayType, @tupletype {
21582181 PlainArrayType getUnderlyingArrayType ( ) {
21592182 result .getArrayElementType ( ) = getArrayElementType ( )
21602183 }
2184+
2185+ /**
2186+ * Gets the number of required tuple elements, that is, excluding optional and rest elements.
2187+ *
2188+ * For example, the minimum length of `[number, string?, ...number[]]` is 1.
2189+ */
2190+ int getMinimumLength ( ) {
2191+ tuple_type_min_length ( this , result )
2192+ }
2193+
2194+ /**
2195+ * Holds if this tuple type ends with a rest element, such as `[number, ...string[]]`.
2196+ */
2197+ predicate hasRestElement ( ) {
2198+ tuple_type_rest ( this )
2199+ }
2200+
2201+ /**
2202+ * Gets the type of the rest element, if there is one.
2203+ *
2204+ * For example, the rest element of `[number, ...string[]]` is `string`.
2205+ */
2206+ Type getRestElementType ( ) {
2207+ hasRestElement ( ) and result = getElementType ( getNumElementType ( ) - 1 )
2208+ }
21612209}
21622210
21632211/**
21642212 * The predefined `any` type.
21652213 */
21662214class AnyType extends Type , @anytype { }
21672215
2216+ /**
2217+ * The predefined `unknown` type.
2218+ */
2219+ class UnknownType extends Type , @unknowntype { }
2220+
21682221/**
21692222 * The predefined `string` type.
21702223 */
0 commit comments