Skip to content

Instantly share code, notes, and snippets.

@cvle
Last active June 26, 2018 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvle/eed44f1b20b5f4ac79f4fe869d581efa to your computer and use it in GitHub Desktop.
Save cvle/eed44f1b20b5f4ac79f4fe869d581efa to your computer and use it in GitHub Desktop.
import React from "react";
type Omit<T, K extends keyof T> = Pick<T, ({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never, [x: number]: never })[keyof T]>;
type InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> =
<P extends TInjectedProps>(
component: React.ComponentType<P>
) => React.ComponentType<Omit<P, keyof TInjectedProps> & TNeedsProps>;
type DefaultingInferableComponentEnhancer<TInjectedProps> =
InferableComponentEnhancerWithProps<TInjectedProps, Partial<TInjectedProps>>;
const withX: DefaultingInferableComponentEnhancer<{x: string}> = null as any;
const withY: DefaultingInferableComponentEnhancer<{y: string}> = null as any;
const withZ: DefaultingInferableComponentEnhancer<{z: string}> = null as any;
const withO: DefaultingInferableComponentEnhancer<{o: string}> = null as any;
const A: React.ComponentType<{a: string, x: string, y: string, z: string, o: string}> = null as any;
const X = withO(withZ(withY(withX(A))));
X.defaultProps = {
a: "I don't exist :-(",
};
@cvle
Copy link
Author

cvle commented Jun 26, 2018


error TS2345: Argument of type 'ComponentType<Pick<Pick<Pick<{ a: string; x: string; y: string; z: string; o: string; }, "a" | "z" | "y" | "o"> & Partial<{ x: string; }>, "a" | "z" | "x" | "o" | undefined> & Partial<{ y: string; }>, any> & Partial<{z: string; }>>' is not assignable to parameter of type 'ComponentType<{ o: string; }>'.
  Type 'ComponentClass<Pick<Pick<Pick<{ a: string; x: string; y: string; z: string; o: string; }, "a" | "z" | "y" | "o"> & Partial<{ x: string; }>, "a" | "z" | "x" | "o" | undefined> & Partial<{ y: string; }>, any> & Partial<{ z: string; }>>' is not assignable to type 'ComponentType<{ o: string; }>'.
    Type 'ComponentClass<Pick<Pick<Pick<{ a: string; x: string; y: string; z: string; o: string; }, "a" | "z" | "y" | "o"> & Partial<{ x: string; }>, "a" | "z" | "x" | "o" | undefined> & Partial<{ y: string;}>, any> & Partial<{ z: string; }>>' is not assignable to type 'StatelessComponent<{ o: string; }>'.
      Types of property 'propTypes' are incompatible.
        Type 'ValidationMap<Pick<Pick<Pick<{ a: string; x: string; y: string; z: string; o: string; }, "a" | "z" | "y" | "o"> & Partial<{ x: string;}>, "a" | "z" | "x" | "o" | undefined> & Partial<{ y: string; }>, any> & Partial<{ z: string; }>> | undefined' is not assignable to type 'ValidationMap<{ o: string; }> | undefined'.
          Type 'ValidationMap<Pick<Pick<Pick<{ a: string; x: string; y: string; z: string; o: string; }, "a" | "z" | "y" | "o"> & Partial<{ x: string; }>, "a" | "z" | "x" | "o" | undefined> & Partial<{ y: string; }>, any> & Partial<{ z: string; }>>' is not assignable to type 'ValidationMap<{ o: string; }> | undefined'.
            Type 'ValidationMap<Pick<Pick<Pick<{ a: string; x: string; y: string; z: string; o: string; }, "a" | "z" | "y" | "o"> & Partial<{ x: string; }>, "a" | "z" | "x" | "o" | undefined> & Partial<{ y: string; }>, any> & Partial<{ z: string; }>>' has no properties in common with type 'ValidationMap<{ o: string; }>'.

76 const X = withO(withZ(withY(withX(A))));
                   ~~~~~~~~~~~~~~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment