Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing excess property errors when assigning to intersection #44942

Closed
OliverJAsh opened this issue Jul 8, 2021 · 1 comment
Closed

Missing excess property errors when assigning to intersection #44942

OliverJAsh opened this issue Jul 8, 2021 · 1 comment
Labels
Bug A bug in TypeScript
Milestone

Comments

@OliverJAsh
Copy link
Contributor

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.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jul 12, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jul 12, 2021
@Andarist
Copy link
Contributor

This was fixed in 4.9, likely by #51140 (4.9.0-dev.20221014 is the first one to report the correct error)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants