Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New 'unknown' top type #24439

Merged
merged 25 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
07a696f
Rename existing unknownType to errorType
ahejlsberg May 26, 2018
8f193b4
Free up one bit in TypeFlags
ahejlsberg May 26, 2018
8b2149e
Accept new baselines
ahejlsberg May 26, 2018
03f464f
Add 'unknown' keyword to scanner/parser/emitter
ahejlsberg May 26, 2018
d225065
Accept new baselines
ahejlsberg May 26, 2018
2003b2a
Implement 'unknown' type in checker
ahejlsberg May 26, 2018
5a0910a
Accept new baselines
ahejlsberg May 26, 2018
b20925a
'null' and 'undefined' are bottom types in non-strictNullChecks mode
ahejlsberg May 26, 2018
9e4d19f
Fixes to keyof and narrowing by typeof check
ahejlsberg May 27, 2018
f63b61c
Accept new baselines
ahejlsberg May 27, 2018
79e7700
{ [P in unknown]: XXX } should resolve to { [x: string]: XXX }
ahejlsberg May 27, 2018
73af0ad
Add tests
ahejlsberg May 27, 2018
5da063f
Accept new baselines
ahejlsberg May 27, 2018
353802c
Check we have non-unknown where we require non-nullable
ahejlsberg May 27, 2018
a83653e
Add new diagnostic
ahejlsberg May 27, 2018
31c73de
Update tests
ahejlsberg May 27, 2018
a4a73df
Accept new baselines
ahejlsberg May 27, 2018
074961f
keyof unknown should be never
ahejlsberg May 29, 2018
c694ffe
Update tests
ahejlsberg May 29, 2018
e98f9a6
Accept new baselines
ahejlsberg May 29, 2018
6b1c84e
Remove eager resolution of distributive conditional types
ahejlsberg May 30, 2018
577662d
Update tests
ahejlsberg May 30, 2018
41ef7a7
Accept new baselines
ahejlsberg May 30, 2018
e22a9d6
Merge branch 'master' into unknownType
ahejlsberg May 30, 2018
8664390
Rename unknownType to errorType in merged code
ahejlsberg May 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
363 changes: 192 additions & 171 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,10 @@
"category": "Error",
"code": 2570
},
"Object is of type 'unknown'.": {
"category": "Error",
"code": 2571
},
"JSX element attributes type '{0}' may not be a union type.": {
"category": "Error",
"code": 2600
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2850,6 +2850,7 @@ namespace ts {
function parseNonArrayType(): TypeNode {
switch (token()) {
case SyntaxKind.AnyKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.StringKeyword:
case SyntaxKind.NumberKeyword:
case SyntaxKind.SymbolKeyword:
Expand Down Expand Up @@ -2907,6 +2908,7 @@ namespace ts {
function isStartOfType(inStartOfParameter?: boolean): boolean {
switch (token()) {
case SyntaxKind.AnyKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.StringKeyword:
case SyntaxKind.NumberKeyword:
case SyntaxKind.BooleanKeyword:
Expand Down
1 change: 1 addition & 0 deletions src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ namespace ts {
"typeof": SyntaxKind.TypeOfKeyword,
"undefined": SyntaxKind.UndefinedKeyword,
"unique": SyntaxKind.UniqueKeyword,
"unknown": SyntaxKind.UnknownKeyword,
"var": SyntaxKind.VarKeyword,
"void": SyntaxKind.VoidKeyword,
"while": SyntaxKind.WhileKeyword,
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ namespace ts {
case SyntaxKind.TypePredicate:
case SyntaxKind.TypeParameter:
case SyntaxKind.AnyKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.BooleanKeyword:
case SyntaxKind.StringKeyword:
case SyntaxKind.NumberKeyword:
Expand Down Expand Up @@ -1907,6 +1908,7 @@ namespace ts {
case SyntaxKind.MappedType:
case SyntaxKind.TypeLiteral:
case SyntaxKind.AnyKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.ThisType:
break;

Expand Down
74 changes: 40 additions & 34 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ namespace ts {
TypeKeyword,
UndefinedKeyword,
UniqueKeyword,
UnknownKeyword,
FromKeyword,
GlobalKeyword,
OfKeyword, // LastKeyword and LastToken and LastContextualKeyword
Expand Down Expand Up @@ -1068,6 +1069,7 @@ namespace ts {

export interface KeywordTypeNode extends TypeNode {
kind: SyntaxKind.AnyKeyword
| SyntaxKind.UnknownKeyword
| SyntaxKind.NumberKeyword
| SyntaxKind.ObjectKeyword
| SyntaxKind.BooleanKeyword
Expand Down Expand Up @@ -3665,42 +3667,43 @@ namespace ts {

export const enum TypeFlags {
Any = 1 << 0,
String = 1 << 1,
Number = 1 << 2,
Boolean = 1 << 3,
Enum = 1 << 4,
StringLiteral = 1 << 5,
NumberLiteral = 1 << 6,
BooleanLiteral = 1 << 7,
EnumLiteral = 1 << 8, // Always combined with StringLiteral, NumberLiteral, or Union
ESSymbol = 1 << 9, // Type of symbol primitive introduced in ES6
UniqueESSymbol = 1 << 10, // unique symbol
Void = 1 << 11,
Undefined = 1 << 12,
Null = 1 << 13,
Never = 1 << 14, // Never type
TypeParameter = 1 << 15, // Type parameter
Object = 1 << 16, // Object type
Union = 1 << 17, // Union (T | U)
Intersection = 1 << 18, // Intersection (T & U)
Index = 1 << 19, // keyof T
IndexedAccess = 1 << 20, // T[K]
Conditional = 1 << 21, // T extends U ? X : Y
Substitution = 1 << 22, // Type parameter substitution
Unknown = 1 << 1,
String = 1 << 2,
Number = 1 << 3,
Boolean = 1 << 4,
Enum = 1 << 5,
StringLiteral = 1 << 6,
NumberLiteral = 1 << 7,
BooleanLiteral = 1 << 8,
EnumLiteral = 1 << 9, // Always combined with StringLiteral, NumberLiteral, or Union
ESSymbol = 1 << 10, // Type of symbol primitive introduced in ES6
UniqueESSymbol = 1 << 11, // unique symbol
Void = 1 << 12,
Undefined = 1 << 13,
Null = 1 << 14,
Never = 1 << 15, // Never type
TypeParameter = 1 << 16, // Type parameter
Object = 1 << 17, // Object type
Union = 1 << 18, // Union (T | U)
Intersection = 1 << 19, // Intersection (T & U)
Index = 1 << 20, // keyof T
IndexedAccess = 1 << 21, // T[K]
Conditional = 1 << 22, // T extends U ? X : Y
Substitution = 1 << 23, // Type parameter substitution
NonPrimitive = 1 << 24, // intrinsic object type
/* @internal */
FreshLiteral = 1 << 23, // Fresh literal or unique type
FreshLiteral = 1 << 25, // Fresh literal or unique type
/* @internal */
ContainsWideningType = 1 << 24, // Type is or contains undefined or null widening type
UnionOfUnitTypes = 1 << 26, // Type is union of unit types
/* @internal */
ContainsObjectLiteral = 1 << 25, // Type is or contains object literal type
ContainsWideningType = 1 << 27, // Type is or contains undefined or null widening type
/* @internal */
ContainsAnyFunctionType = 1 << 26, // Type is or contains the anyFunctionType
NonPrimitive = 1 << 27, // intrinsic object type
ContainsObjectLiteral = 1 << 28, // Type is or contains object literal type
/* @internal */
UnionOfUnitTypes = 1 << 28, // Type is union of unit types
/* @internal */
GenericMappedType = 1 << 29, // Flag used by maybeTypeOfKind
ContainsAnyFunctionType = 1 << 29, // Type is or contains the anyFunctionType

/* @internal */
AnyOrUnknown = Any | Unknown,
/* @internal */
Nullable = Undefined | Null,
Literal = StringLiteral | NumberLiteral | BooleanLiteral,
Expand All @@ -3712,7 +3715,7 @@ namespace ts {
DefinitelyFalsy = StringLiteral | NumberLiteral | BooleanLiteral | Void | Undefined | Null,
PossiblyFalsy = DefinitelyFalsy | String | Number | Boolean,
/* @internal */
Intrinsic = Any | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive,
Intrinsic = Any | Unknown | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive,
/* @internal */
Primitive = String | Number | Boolean | Enum | EnumLiteral | ESSymbol | Void | Undefined | Null | Literal | UniqueESSymbol,
StringLike = String | StringLiteral,
Expand All @@ -3733,8 +3736,8 @@ namespace ts {

// 'Narrowable' types are types where narrowing actually narrows.
// This *should* be every type other than null, undefined, void, and never
Narrowable = Any | StructuredOrInstantiable | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
NotUnionOrUnit = Any | ESSymbol | Object | NonPrimitive,
Narrowable = Any | Unknown | StructuredOrInstantiable | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
NotUnionOrUnit = Any | Unknown | ESSymbol | Object | NonPrimitive,
/* @internal */
NotUnit = Any | String | Number | Boolean | Enum | ESSymbol | Void | Never | StructuredOrInstantiable,
/* @internal */
Expand All @@ -3749,7 +3752,10 @@ namespace ts {
/* @internal */
EmptyObject = ContainsAnyFunctionType,
/* @internal */
ConstructionFlags = NonWideningType | Wildcard | EmptyObject
ConstructionFlags = NonWideningType | Wildcard | EmptyObject,
// The following flag is used for different purposes by maybeTypeOfKind
/* @internal */
GenericMappedType = ContainsWideningType
}

export type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression;
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ namespace ts {

switch (node.kind) {
case SyntaxKind.AnyKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.NumberKeyword:
case SyntaxKind.StringKeyword:
case SyntaxKind.BooleanKeyword:
Expand Down Expand Up @@ -5777,6 +5778,7 @@ namespace ts {
function isTypeNodeKind(kind: SyntaxKind) {
return (kind >= SyntaxKind.FirstTypeNode && kind <= SyntaxKind.LastTypeNode)
|| kind === SyntaxKind.AnyKeyword
|| kind === SyntaxKind.UnknownKeyword
|| kind === SyntaxKind.NumberKeyword
|| kind === SyntaxKind.ObjectKeyword
|| kind === SyntaxKind.BooleanKeyword
Expand Down
Loading