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 0600a27

Browse filesBrowse files
HerringtonDarkholmemhegazy
authored andcommitted
fix microsoft#15447: object is empty object type (microsoft#16290)
1 parent a6e1ced commit 0600a27
Copy full SHA for 0600a27

4 files changed

+33-2Lines changed: 33 additions & 2 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/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8599,6 +8599,7 @@ namespace ts {
85998599

86008600
function isEmptyObjectType(type: Type): boolean {
86018601
return type.flags & TypeFlags.Object ? isEmptyResolvedType(resolveStructuredTypeMembers(<ObjectType>type)) :
8602+
type.flags & TypeFlags.NonPrimitive ? true :
86028603
type.flags & TypeFlags.Union ? forEach((<UnionType>type).types, isEmptyObjectType) :
86038604
type.flags & TypeFlags.Intersection ? !forEach((<UnionType>type).types, t => !isEmptyObjectType(t)) :
86048605
false;
Collapse file
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(1,5): error TS2322: Type '""' is not assignable to type 'object & string'.
22
Type '""' is not assignable to type 'object'.
3-
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(3,1): error TS2322: Type 'string' is not assignable to type 'object & string'.
3+
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(3,5): error TS2322: Type '123' is not assignable to type 'object & {}'.
4+
Type '123' is not assignable to type 'object'.
5+
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(4,1): error TS2322: Type 'string' is not assignable to type 'object & string'.
46
Type 'string' is not assignable to type 'object'.
7+
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(8,38): error TS2322: Type '{ bar: string; }' is not assignable to type 'object & { err: string; }'.
8+
Object literal may only specify known properties, and 'bar' does not exist in type 'object & { err: string; }'.
59

610

7-
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts (2 errors) ====
11+
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts (4 errors) ====
812
var a: object & string = ""; // error
913
~
1014
!!! error TS2322: Type '""' is not assignable to type 'object & string'.
1115
!!! error TS2322: Type '""' is not assignable to type 'object'.
1216
var b: object | string = ""; // ok
17+
var c: object & {} = 123; // error
18+
~
19+
!!! error TS2322: Type '123' is not assignable to type 'object & {}'.
20+
!!! error TS2322: Type '123' is not assignable to type 'object'.
1321
a = b; // error
1422
~
1523
!!! error TS2322: Type 'string' is not assignable to type 'object & string'.
1624
!!! error TS2322: Type 'string' is not assignable to type 'object'.
1725
b = a; // ok
26+
27+
const foo: object & {} = {bar: 'bar'}; // ok
28+
const bar: object & {err: string} = {bar: 'bar'}; // error
29+
~~~~~~~~~~
30+
!!! error TS2322: Type '{ bar: string; }' is not assignable to type 'object & { err: string; }'.
31+
!!! error TS2322: Object literal may only specify known properties, and 'bar' does not exist in type 'object & { err: string; }'.
1832

Collapse file
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
//// [nonPrimitiveUnionIntersection.ts]
22
var a: object & string = ""; // error
33
var b: object | string = ""; // ok
4+
var c: object & {} = 123; // error
45
a = b; // error
56
b = a; // ok
7+
8+
const foo: object & {} = {bar: 'bar'}; // ok
9+
const bar: object & {err: string} = {bar: 'bar'}; // error
610

711

812
//// [nonPrimitiveUnionIntersection.js]
913
var a = ""; // error
1014
var b = ""; // ok
15+
var c = 123; // error
1116
a = b; // error
1217
b = a; // ok
18+
var foo = { bar: 'bar' }; // ok
19+
var bar = { bar: 'bar' }; // error
1320

1421

1522
//// [nonPrimitiveUnionIntersection.d.ts]
1623
declare var a: object & string;
1724
declare var b: object | string;
25+
declare var c: object & {};
26+
declare const foo: object & {};
27+
declare const bar: object & {
28+
err: string;
29+
};
Collapse file
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// @declaration: true
22
var a: object & string = ""; // error
33
var b: object | string = ""; // ok
4+
var c: object & {} = 123; // error
45
a = b; // error
56
b = a; // ok
7+
8+
const foo: object & {} = {bar: 'bar'}; // ok
9+
const bar: object & {err: string} = {bar: 'bar'}; // error

0 commit comments

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