Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ebe2fdb

Browse filesBrowse files
Fix microsoft#1809, introduce non primitive type
1 parent c563e83 commit ebe2fdb
Copy full SHA for ebe2fdb

4 files changed

+19Lines changed: 19 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/binder.ts‎

Copy file name to clipboardExpand all lines: src/compiler/binder.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,6 +3145,7 @@ namespace ts {
31453145
case SyntaxKind.AnyKeyword:
31463146
case SyntaxKind.NumberKeyword:
31473147
case SyntaxKind.NeverKeyword:
3148+
case SyntaxKind.ObjectKeyword:
31483149
case SyntaxKind.StringKeyword:
31493150
case SyntaxKind.BooleanKeyword:
31503151
case SyntaxKind.SymbolKeyword:
@@ -3343,6 +3344,7 @@ namespace ts {
33433344
case SyntaxKind.NumberKeyword:
33443345
case SyntaxKind.NeverKeyword:
33453346
case SyntaxKind.StringKeyword:
3347+
case SyntaxKind.ObjectKeyword:
33463348
case SyntaxKind.BooleanKeyword:
33473349
case SyntaxKind.SymbolKeyword:
33483350
case SyntaxKind.VoidKeyword:
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ namespace ts {
146146
const silentNeverType = createIntrinsicType(TypeFlags.Never, "never");
147147

148148
const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
149+
const nonPrimitiveType = createNonPrimitiveType();
149150

150151
const emptyTypeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral | SymbolFlags.Transient, "__type");
151152
emptyTypeLiteralSymbol.members = createMap<Symbol>();
@@ -1684,6 +1685,14 @@ namespace ts {
16841685
return type;
16851686
}
16861687

1688+
function createNonPrimitiveType(): NonPrimitiveType {
1689+
const type = <NonPrimitiveType>setStructuredTypeMembers(
1690+
createObjectType(ObjectFlags.NonPrimitive, undefined),
1691+
emptySymbols, emptyArray, emptyArray, undefined, undefined);
1692+
type.intrinsicName = "object";
1693+
return type;
1694+
}
1695+
16871696
function createObjectType(objectFlags: ObjectFlags, symbol?: Symbol): ObjectType {
16881697
const type = <ObjectType>createType(TypeFlags.Object);
16891698
type.objectFlags = objectFlags;
@@ -4178,6 +4187,7 @@ namespace ts {
41784187
case SyntaxKind.NumberKeyword:
41794188
case SyntaxKind.BooleanKeyword:
41804189
case SyntaxKind.SymbolKeyword:
4190+
case SyntaxKind.ObjectKeyword:
41814191
case SyntaxKind.VoidKeyword:
41824192
case SyntaxKind.UndefinedKeyword:
41834193
case SyntaxKind.NullKeyword:
@@ -6384,6 +6394,8 @@ namespace ts {
63846394
return nullType;
63856395
case SyntaxKind.NeverKeyword:
63866396
return neverType;
6397+
case SyntaxKind.ObjectKeyword:
6398+
return nonPrimitiveType;
63876399
case SyntaxKind.JSDocNullKeyword:
63886400
return nullType;
63896401
case SyntaxKind.JSDocUndefinedKeyword:
@@ -7139,6 +7151,7 @@ namespace ts {
71397151
if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum && isEnumTypeRelatedTo(<EnumType>source, <EnumType>target, errorReporter)) return true;
71407152
if (source.flags & TypeFlags.Undefined && (!strictNullChecks || target.flags & (TypeFlags.Undefined | TypeFlags.Void))) return true;
71417153
if (source.flags & TypeFlags.Null && (!strictNullChecks || target.flags & TypeFlags.Null)) return true;
7154+
if (source.flags & TypeFlags.Object && (<ObjectType>source).objectFlags & ObjectFlags.NonPrimitive && target.flags & TypeFlags.Primitive) return false;
71427155
if (relation === assignableRelation || relation === comparableRelation) {
71437156
if (source.flags & TypeFlags.Any) return true;
71447157
if ((source.flags & TypeFlags.Number | source.flags & TypeFlags.NumberLiteral) && target.flags & TypeFlags.EnumLike) return true;
Collapse file

‎src/compiler/scanner.ts‎

Copy file name to clipboardExpand all lines: src/compiler/scanner.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ namespace ts {
9898
"new": SyntaxKind.NewKeyword,
9999
"null": SyntaxKind.NullKeyword,
100100
"number": SyntaxKind.NumberKeyword,
101+
"object": SyntaxKind.ObjectKeyword,
101102
"package": SyntaxKind.PackageKeyword,
102103
"private": SyntaxKind.PrivateKeyword,
103104
"protected": SyntaxKind.ProtectedKeyword,
Collapse file

‎src/compiler/types.ts‎

Copy file name to clipboardExpand all lines: src/compiler/types.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ namespace ts {
175175
ReadonlyKeyword,
176176
RequireKeyword,
177177
NumberKeyword,
178+
ObjectKeyword,
178179
SetKeyword,
179180
StringKeyword,
180181
SymbolKeyword,
@@ -816,6 +817,7 @@ namespace ts {
816817
export interface KeywordTypeNode extends TypeNode {
817818
kind: SyntaxKind.AnyKeyword
818819
| SyntaxKind.NumberKeyword
820+
| SyntaxKind.ObjectKeyword
819821
| SyntaxKind.BooleanKeyword
820822
| SyntaxKind.StringKeyword
821823
| SyntaxKind.SymbolKeyword
@@ -2857,6 +2859,7 @@ namespace ts {
28572859
ObjectLiteral = 1 << 7, // Originates in an object literal
28582860
EvolvingArray = 1 << 8, // Evolving array type
28592861
ObjectLiteralPatternWithComputedProperties = 1 << 9, // Object literal pattern with computed properties
2862+
NonPrimitive = 1 << 10, // NonPrimitive object type
28602863
ClassOrInterface = Class | Interface
28612864
}
28622865

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.