fix #15447: `object` is empty object type by HerringtonDarkholme · Pull Request #16290 · microsoft/TypeScript · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/compiler/checker.ts
18 changes: 16 additions & 2 deletions tests/baselines/reference/nonPrimitiveUnionIntersection.errors.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(1,5): error TS2322: Type '""' is not assignable to type 'object & string'.
Type '""' is not assignable to type 'object'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(3,1): error TS2322: Type 'string' is not assignable to type 'object & string'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(3,5): error TS2322: Type '123' is not assignable to type 'object & {}'.
Type '123' is not assignable to type 'object'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(4,1): error TS2322: Type 'string' is not assignable to type 'object & string'.
Type 'string' is not assignable to type 'object'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(8,38): error TS2322: Type '{ bar: string; }' is not assignable to type 'object & { err: string; }'.
Object literal may only specify known properties, and 'bar' does not exist in type 'object & { err: string; }'.


==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts (2 errors) ====
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts (4 errors) ====
var a: object & string = ""; // error
~
!!! error TS2322: Type '""' is not assignable to type 'object & string'.
!!! error TS2322: Type '""' is not assignable to type 'object'.
var b: object | string = ""; // ok
var c: object & {} = 123; // error
~
!!! error TS2322: Type '123' is not assignable to type 'object & {}'.
!!! error TS2322: Type '123' is not assignable to type 'object'.
a = b; // error
~
!!! error TS2322: Type 'string' is not assignable to type 'object & string'.
!!! error TS2322: Type 'string' is not assignable to type 'object'.
b = a; // ok

const foo: object & {} = {bar: 'bar'}; // ok
const bar: object & {err: string} = {bar: 'bar'}; // error
~~~~~~~~~~
!!! error TS2322: Type '{ bar: string; }' is not assignable to type 'object & { err: string; }'.
!!! error TS2322: Object literal may only specify known properties, and 'bar' does not exist in type 'object & { err: string; }'.

12 changes: 12 additions & 0 deletions tests/baselines/reference/nonPrimitiveUnionIntersection.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
//// [nonPrimitiveUnionIntersection.ts]
var a: object & string = ""; // error
var b: object | string = ""; // ok
var c: object & {} = 123; // error
a = b; // error
b = a; // ok

const foo: object & {} = {bar: 'bar'}; // ok
const bar: object & {err: string} = {bar: 'bar'}; // error


//// [nonPrimitiveUnionIntersection.js]
var a = ""; // error
var b = ""; // ok
var c = 123; // error
a = b; // error
b = a; // ok
var foo = { bar: 'bar' }; // ok
var bar = { bar: 'bar' }; // error


//// [nonPrimitiveUnionIntersection.d.ts]
declare var a: object & string;
declare var b: object | string;
declare var c: object & {};
declare const foo: object & {};
declare const bar: object & {
err: string;
};