Skip to content

Define Intersection Types that include object literal #7649

Description

@syuilo

Nested Intersection Types are supported?

Code:

interface A {
    nested: {
        kyoppie: string;
    }
}

interface B {
    nested: {
        yuppie: string;
    }
}

const ab: A & B = {
    nested: {
        kyoppie: 'aaa',
        yuppie: 'bbb' // <- Error
    }
};

Got:

error TS2322:
Type '{ nested: { kyoppie: string; yuppie: string; }; }' is not assignable to type 'A & B'
  Type '{ nested: { kyoppie: string; yuppie: string; }; }' is not assignable to type 'A'.
    Types of property 'nested' are incompatible.
      Type '{ kyoppie: string; yuppie: string; }' is not assignable to type '{ kyoppie: string; }'.
        Object literal may only specify known properties, and 'yuppie' does not exist in type '{ kyoppie: string; }'.

My TypeScript Version: 1.8.9


Sorry my bad English. Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions