Skip to content

Commit

Permalink
fix: replace slow Omit type
Browse files Browse the repository at this point in the history
  • Loading branch information
gineika authored and quantizor committed Jul 3, 2023
1 parent f073ac8 commit 3ddd2a6
Showing 1 changed file with 7 additions and 3 deletions.
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;

0 comments on commit 3ddd2a6

Please sign in to comment.