sindresorhus / type-fest

A collection of essential TypeScript types
Creative Commons Zero v1.0 Universal
14.36k stars 546 forks source link

Improve `Simplify` type? #172

Open sindresorhus opened 3 years ago

sindresorhus commented 3 years ago

I think https://github.com/sindresorhus/type-fest/pull/157/files#diff-520a63fe400b4b92fa3ccc14cabc1d84153987354c3f242deddfaeff0a7deae2 could be useful for others too.

Upvote & Fund

Fund with Polar

ianobermiller commented 3 years ago

Is the question here whether or not type-fest should export Simplify? I found this type and was hoping it was exported, since we have components that compose their props as below, and being able to flatten them for the editor would be really useful:

type Props = PropTypes.Position & PropTypes.Animation & {
    componentSpecificProp: string,
    ...,
};

Even in its current state of only accepting object types it would be super useful, so I don't think exporting it should be dependent on adding more functionality.

sindresorhus commented 3 years ago

The questions are not blocking. Anyone are free to submit a PR to expose it. 👍

voxpelli commented 3 years ago

Should it also support array like in https://gist.github.com/ClickerMonkey/a081b990b9b14215141fb6248cef4dc4#file-types-ts-L49-L54 ?

If there are no downsides from it, then I think it makes sense 👍 Though maybe await a use case in our code or a request for it? Else we may not even discover if it breaks eventually.

How can we test it?

We would probably have to go some odd route for this, like maybe pull out the language server itself and inspect the output?

Xriuk commented 5 months ago

Hello, I think that both Simplify and SimplifyDeep should also simplify arrays, currently this is not working:

type A = {
    Prop: {
        Prop1: string;
    }[];
};
type B = {
    Prop: {
        Prop2: boolean;
    }[];
};

type C = Simplify<A & B>;
type C = SimplifyDeep<A & B>;

Both produce a type like this:

type C = {
    Prop: {
        Prop1: string;
    }[] & {
        Prop2: boolean;
    }[];
}