Skip to content

Commit 03f464f

Browse files
committed
Add 'unknown' keyword to scanner/parser/emitter
1 parent 8b2149e commit 03f464f

5 files changed

Lines changed: 43 additions & 31 deletions

File tree

src/compiler/parser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,6 +2850,7 @@ namespace ts {
28502850
function parseNonArrayType(): TypeNode {
28512851
switch (token()) {
28522852
case SyntaxKind.AnyKeyword:
2853+
case SyntaxKind.UnknownKeyword:
28532854
case SyntaxKind.StringKeyword:
28542855
case SyntaxKind.NumberKeyword:
28552856
case SyntaxKind.SymbolKeyword:
@@ -2907,6 +2908,7 @@ namespace ts {
29072908
function isStartOfType(inStartOfParameter?: boolean): boolean {
29082909
switch (token()) {
29092910
case SyntaxKind.AnyKeyword:
2911+
case SyntaxKind.UnknownKeyword:
29102912
case SyntaxKind.StringKeyword:
29112913
case SyntaxKind.NumberKeyword:
29122914
case SyntaxKind.BooleanKeyword:

src/compiler/scanner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ namespace ts {
124124
"typeof": SyntaxKind.TypeOfKeyword,
125125
"undefined": SyntaxKind.UndefinedKeyword,
126126
"unique": SyntaxKind.UniqueKeyword,
127+
"unknown": SyntaxKind.UnknownKeyword,
127128
"var": SyntaxKind.VarKeyword,
128129
"void": SyntaxKind.VoidKeyword,
129130
"while": SyntaxKind.WhileKeyword,

src/compiler/transformers/ts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ namespace ts {
384384
case SyntaxKind.TypePredicate:
385385
case SyntaxKind.TypeParameter:
386386
case SyntaxKind.AnyKeyword:
387+
case SyntaxKind.UnknownKeyword:
387388
case SyntaxKind.BooleanKeyword:
388389
case SyntaxKind.StringKeyword:
389390
case SyntaxKind.NumberKeyword:
@@ -1907,6 +1908,7 @@ namespace ts {
19071908
case SyntaxKind.MappedType:
19081909
case SyntaxKind.TypeLiteral:
19091910
case SyntaxKind.AnyKeyword:
1911+
case SyntaxKind.UnknownKeyword:
19101912
case SyntaxKind.ThisType:
19111913
break;
19121914

src/compiler/types.ts

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ namespace ts {
241241
TypeKeyword,
242242
UndefinedKeyword,
243243
UniqueKeyword,
244+
UnknownKeyword,
244245
FromKeyword,
245246
GlobalKeyword,
246247
OfKeyword, // LastKeyword and LastToken and LastContextualKeyword
@@ -1068,6 +1069,7 @@ namespace ts {
10681069

10691070
export interface KeywordTypeNode extends TypeNode {
10701071
kind: SyntaxKind.AnyKeyword
1072+
| SyntaxKind.UnknownKeyword
10711073
| SyntaxKind.NumberKeyword
10721074
| SyntaxKind.ObjectKeyword
10731075
| SyntaxKind.BooleanKeyword
@@ -3665,40 +3667,43 @@ namespace ts {
36653667

36663668
export const enum TypeFlags {
36673669
Any = 1 << 0,
3668-
String = 1 << 1,
3669-
Number = 1 << 2,
3670-
Boolean = 1 << 3,
3671-
Enum = 1 << 4,
3672-
StringLiteral = 1 << 5,
3673-
NumberLiteral = 1 << 6,
3674-
BooleanLiteral = 1 << 7,
3675-
EnumLiteral = 1 << 8, // Always combined with StringLiteral, NumberLiteral, or Union
3676-
ESSymbol = 1 << 9, // Type of symbol primitive introduced in ES6
3677-
UniqueESSymbol = 1 << 10, // unique symbol
3678-
Void = 1 << 11,
3679-
Undefined = 1 << 12,
3680-
Null = 1 << 13,
3681-
Never = 1 << 14, // Never type
3682-
TypeParameter = 1 << 15, // Type parameter
3683-
Object = 1 << 16, // Object type
3684-
Union = 1 << 17, // Union (T | U)
3685-
Intersection = 1 << 18, // Intersection (T & U)
3686-
Index = 1 << 19, // keyof T
3687-
IndexedAccess = 1 << 20, // T[K]
3688-
Conditional = 1 << 21, // T extends U ? X : Y
3689-
Substitution = 1 << 22, // Type parameter substitution
3690-
NonPrimitive = 1 << 23, // intrinsic object type
3670+
Unknown = 1 << 1,
3671+
String = 1 << 2,
3672+
Number = 1 << 3,
3673+
Boolean = 1 << 4,
3674+
Enum = 1 << 5,
3675+
StringLiteral = 1 << 6,
3676+
NumberLiteral = 1 << 7,
3677+
BooleanLiteral = 1 << 8,
3678+
EnumLiteral = 1 << 9, // Always combined with StringLiteral, NumberLiteral, or Union
3679+
ESSymbol = 1 << 10, // Type of symbol primitive introduced in ES6
3680+
UniqueESSymbol = 1 << 11, // unique symbol
3681+
Void = 1 << 12,
3682+
Undefined = 1 << 13,
3683+
Null = 1 << 14,
3684+
Never = 1 << 15, // Never type
3685+
TypeParameter = 1 << 16, // Type parameter
3686+
Object = 1 << 17, // Object type
3687+
Union = 1 << 18, // Union (T | U)
3688+
Intersection = 1 << 19, // Intersection (T & U)
3689+
Index = 1 << 20, // keyof T
3690+
IndexedAccess = 1 << 21, // T[K]
3691+
Conditional = 1 << 22, // T extends U ? X : Y
3692+
Substitution = 1 << 23, // Type parameter substitution
3693+
NonPrimitive = 1 << 24, // intrinsic object type
36913694
/* @internal */
3692-
FreshLiteral = 1 << 24, // Fresh literal or unique type
3695+
FreshLiteral = 1 << 25, // Fresh literal or unique type
36933696
/* @internal */
3694-
UnionOfUnitTypes = 1 << 25, // Type is union of unit types
3697+
UnionOfUnitTypes = 1 << 26, // Type is union of unit types
36953698
/* @internal */
3696-
ContainsWideningType = 1 << 26, // Type is or contains undefined or null widening type
3699+
ContainsWideningType = 1 << 27, // Type is or contains undefined or null widening type
36973700
/* @internal */
3698-
ContainsObjectLiteral = 1 << 27, // Type is or contains object literal type
3701+
ContainsObjectLiteral = 1 << 28, // Type is or contains object literal type
36993702
/* @internal */
3700-
ContainsAnyFunctionType = 1 << 28, // Type is or contains the anyFunctionType
3703+
ContainsAnyFunctionType = 1 << 29, // Type is or contains the anyFunctionType
37013704

3705+
/* @internal */
3706+
AnyOrUnknown = Any | Unknown,
37023707
/* @internal */
37033708
Nullable = Undefined | Null,
37043709
Literal = StringLiteral | NumberLiteral | BooleanLiteral,
@@ -3710,7 +3715,7 @@ namespace ts {
37103715
DefinitelyFalsy = StringLiteral | NumberLiteral | BooleanLiteral | Void | Undefined | Null,
37113716
PossiblyFalsy = DefinitelyFalsy | String | Number | Boolean,
37123717
/* @internal */
3713-
Intrinsic = Any | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive,
3718+
Intrinsic = Any | Unknown | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive,
37143719
/* @internal */
37153720
Primitive = String | Number | Boolean | Enum | EnumLiteral | ESSymbol | Void | Undefined | Null | Literal | UniqueESSymbol,
37163721
StringLike = String | StringLiteral,
@@ -3731,8 +3736,8 @@ namespace ts {
37313736

37323737
// 'Narrowable' types are types where narrowing actually narrows.
37333738
// This *should* be every type other than null, undefined, void, and never
3734-
Narrowable = Any | StructuredOrInstantiable | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
3735-
NotUnionOrUnit = Any | ESSymbol | Object | NonPrimitive,
3739+
Narrowable = Any | Unknown | StructuredOrInstantiable | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
3740+
NotUnionOrUnit = Any | Unknown | ESSymbol | Object | NonPrimitive,
37363741
/* @internal */
37373742
NotUnit = Any | String | Number | Boolean | Enum | ESSymbol | Void | Never | StructuredOrInstantiable,
37383743
/* @internal */

src/compiler/utilities.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ namespace ts {
810810

811811
switch (node.kind) {
812812
case SyntaxKind.AnyKeyword:
813+
case SyntaxKind.UnknownKeyword:
813814
case SyntaxKind.NumberKeyword:
814815
case SyntaxKind.StringKeyword:
815816
case SyntaxKind.BooleanKeyword:
@@ -5777,6 +5778,7 @@ namespace ts {
57775778
function isTypeNodeKind(kind: SyntaxKind) {
57785779
return (kind >= SyntaxKind.FirstTypeNode && kind <= SyntaxKind.LastTypeNode)
57795780
|| kind === SyntaxKind.AnyKeyword
5781+
|| kind === SyntaxKind.UnknownKeyword
57805782
|| kind === SyntaxKind.NumberKeyword
57815783
|| kind === SyntaxKind.ObjectKeyword
57825784
|| kind === SyntaxKind.BooleanKeyword

0 commit comments

Comments
 (0)