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

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

Copy link
Copy link
@voithos

Description

@voithos
Issue body actions

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;
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou 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

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