Skip to content

Error when using {} intersection types with object literal #15447

Description

@voithos

TypeScript Version: 2.3.1
Code

const foo: object & {} = {bar: 'bar'};

Expected behavior:
No error.

Actual behavior:
I get the following error:

Type '{ bar: string; }' is not assignable to type 'object & {}'.
  Object literal may only specify known properties, and 'bar' does not exist in type 'object & {}'.

This error is not present in 2.2 or 2.3-rc. Interestingly enough, the following all work fine:

const foo1: object = {bar: 'bar'};
const foo2: {} = {bar: 'bar'};

class Bar {}
const bar = new Bar();
const foo3: Bar & {} = bar;

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions