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

fix: replace slow Omit type #4068

Merged
merged 4 commits into from
Jul 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/styled-components/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export type BaseObject = {};
// from https://stackoverflow.com/a/69852402
export type OmitNever<T> = { [K in keyof T as T[K] extends never ? never : K]: T[K] };

type FastOmit<T, U extends string | number | symbol> = {
[K in keyof T as K extends U ? never : K]: T[K];
}

export type Runtime = 'web' | 'native';

export type AnyComponent<P = any> = ExoticComponentWithDisplayName<P> | React.ComponentType<P>;
Expand Down Expand Up @@ -161,15 +165,15 @@ export type PolymorphicComponentProps<
ForwardedAsTargetProps extends object = ForwardedAsTarget extends KnownTarget
? React.ComponentPropsWithoutRef<ForwardedAsTarget>
: {}
> = Omit<
> = FastOmit<
Substitute<
BaseProps,
// "as" wins over "forwardedAs" when it comes to prop interface
Substitute<ForwardedAsTargetProps, AsTargetProps>
>,
keyof ExecutionProps
> &
Omit<ExecutionProps, 'as' | 'forwardedAs'> & {
FastOmit<ExecutionProps, 'as' | 'forwardedAs'> & {
as?: AsTarget;
forwardedAs?: ForwardedAsTarget;
};
Expand Down Expand Up @@ -259,4 +263,4 @@ export type CSSProp = Interpolation<any>;
// Prevents TypeScript from inferring generic argument
export type NoInfer<T> = [T][T extends any ? 0 : never];

export type Substitute<A extends object, B extends object> = Omit<A, keyof B> & B;
export type Substitute<A extends object, B extends object> = FastOmit<A, keyof B> & B;