Skip to content

Missing excess property errors when assigning to intersectionΒ #44942

@OliverJAsh

Description

@OliverJAsh

Bug Report

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about excess property checking

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Props = { foo: string };

type Demo = {
    props: Props;
} & {
    props: Props;
};

type Collection = {
    demo: Demo;
} & {
    demo: Demo;
};

const t1: Collection = {
    demo: {
        props: {
            foo: 'foo',
            bar: 1, // expected error due to excess prop, but got none ❌
        },
    },
};

If we remove one of the intersections, excess property checks kick in again.

This is clearly a contrived example however I have reduced it from a much more complicated example where we do actually need to use intersections in a similar way. I can elaborate if needed.

I have been able to workaround the issue using this Compact helper:

type Compact<A> = A extends Function ? A : { [K in keyof A]: A[K] } & {};

type Collection = Compact<{
    demo: Demo;
} & {
    demo: Demo;
}>;

πŸ™ Actual behavior

See comment in code above.

πŸ™‚ Expected behavior

See comment in code above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions