Skip to content

Commit 9a9bbac

Browse files
committed
TypeScript: support syntax for unknown types
1 parent 4a9eb0f commit 9a9bbac

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

javascript/ql/src/semmle/javascript/TypeScript.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| tst.ts:137:18:137:24 | unknown |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import javascript
2+
3+
from TypeExpr type
4+
where type.isUnknownKeyword()
5+
select type

javascript/ql/test/library-tests/TypeScript/TypeAnnotations/tst.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,4 @@ let tupleWithOptionalElement: [number, string, number?];
134134
let emptyTuple: [];
135135
let tupleWithRestElement: [number, ...string[]];
136136
let tupleWithOptionalAndRestElements: [number, string?, ...number[]];
137+
let unknownType: unknown;

0 commit comments

Comments
 (0)