TypeScript: support syntax for unknown types

This commit is contained in:
Asger F
2018-08-20 14:42:50 +01:00
parent 4a9eb0fd3f
commit 9a9bbac99e
4 changed files with 11 additions and 0 deletions

View File

@@ -686,6 +686,9 @@ class TypeExpr extends ExprOrType, @typeexpr {
/** Holds if this is the `object` type. */ /** Holds if this is the `object` type. */
predicate isObjectKeyword() { none() } predicate isObjectKeyword() { none() }
/** Holds if this is the `unknown` type. */
predicate isUnknownKeyword() { none() }
/** Gets this type expression, with any surrounding parentheses removed. */ /** Gets this type expression, with any surrounding parentheses removed. */
override TypeExpr stripParens() { override TypeExpr stripParens() {
result = this result = this
@@ -725,6 +728,7 @@ private class KeywordTypeExpr extends @keywordtypeexpr, TypeExpr {
override predicate isSymbol() { getName() = "symbol" } override predicate isSymbol() { getName() = "symbol" }
override predicate isUniqueSymbol() { getName() = "unique symbol" } override predicate isUniqueSymbol() { getName() = "unique symbol" }
override predicate isObjectKeyword() { getName() = "object" } override predicate isObjectKeyword() { getName() = "object" }
override predicate isUnknownKeyword() { getName() = "unknown" }
} }
/** /**

View File

@@ -0,0 +1 @@
| tst.ts:137:18:137:24 | unknown |

View File

@@ -0,0 +1,5 @@
import javascript
from TypeExpr type
where type.isUnknownKeyword()
select type

View File

@@ -134,3 +134,4 @@ let tupleWithOptionalElement: [number, string, number?];
let emptyTuple: []; let emptyTuple: [];
let tupleWithRestElement: [number, ...string[]]; let tupleWithRestElement: [number, ...string[]];
let tupleWithOptionalAndRestElements: [number, string?, ...number[]]; let tupleWithOptionalAndRestElements: [number, string?, ...number[]];
let unknownType: unknown;