|
| 1 | +styledComponentsInstantiaionLimitNotReached.ts(171,8): error TS2615: Type of property 'propTypes' circularly references itself in mapped type 'ForwardRefExoticBase<Omit<Omit<any, any> & Partial<Pick<any, any>>, "theme"> & { theme?: any; } & WithChildrenIfReactComponentClass<StyledComponentInnerComponent<WithC>>>'. |
| 2 | + |
| 3 | + |
| 4 | +==== styledComponentsInstantiaionLimitNotReached.ts (1 errors) ==== |
| 5 | + /// <reference path="/.lib/react16.d.ts" /> |
| 6 | + import * as React from "react"; |
| 7 | + |
| 8 | + interface REACT_STATICS { |
| 9 | + childContextTypes: true; |
| 10 | + contextType: true; |
| 11 | + contextTypes: true; |
| 12 | + defaultProps: true; |
| 13 | + displayName: true; |
| 14 | + getDefaultProps: true; |
| 15 | + getDerivedStateFromError: true; |
| 16 | + getDerivedStateFromProps: true; |
| 17 | + mixins: true; |
| 18 | + propTypes: true; |
| 19 | + type: true; |
| 20 | + } |
| 21 | + |
| 22 | + interface KNOWN_STATICS { |
| 23 | + name: true; |
| 24 | + length: true; |
| 25 | + prototype: true; |
| 26 | + caller: true; |
| 27 | + callee: true; |
| 28 | + arguments: true; |
| 29 | + arity: true; |
| 30 | + } |
| 31 | + |
| 32 | + interface MEMO_STATICS { |
| 33 | + '$$typeof': true; |
| 34 | + compare: true; |
| 35 | + defaultProps: true; |
| 36 | + displayName: true; |
| 37 | + propTypes: true; |
| 38 | + type: true; |
| 39 | + } |
| 40 | + |
| 41 | + interface FORWARD_REF_STATICS { |
| 42 | + '$$typeof': true; |
| 43 | + render: true; |
| 44 | + defaultProps: true; |
| 45 | + displayName: true; |
| 46 | + propTypes: true; |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + type NonReactStatics< |
| 51 | + S extends React.ComponentType<any>, |
| 52 | + C extends { |
| 53 | + [key: string]: true |
| 54 | + } = {} |
| 55 | + > = { |
| 56 | + [key in Exclude< |
| 57 | + keyof S, |
| 58 | + S extends React.MemoExoticComponent<any> |
| 59 | + ? keyof MEMO_STATICS | keyof C |
| 60 | + : S extends React.ForwardRefExoticComponent<any> |
| 61 | + ? keyof FORWARD_REF_STATICS | keyof C |
| 62 | + : keyof REACT_STATICS | keyof KNOWN_STATICS | keyof C |
| 63 | + >]: S[key] |
| 64 | + }; |
| 65 | + |
| 66 | + export type AnyStyledComponent = StyledComponent<any, any, any, any> | StyledComponent<any, any, any>; |
| 67 | + export type StyledComponent< |
| 68 | + C extends keyof JSX.IntrinsicElements | React.ComponentType<any>, |
| 69 | + T extends object, |
| 70 | + O extends object = {}, |
| 71 | + A extends keyof any = never |
| 72 | + > = // the "string" allows this to be used as an object key |
| 73 | + // I really want to avoid this if possible but it's the only way to use nesting with object styles... |
| 74 | + string & |
| 75 | + StyledComponentBase<C, T, O, A> & |
| 76 | + NonReactStatics<C extends React.ComponentType<any> ? C : never>; |
| 77 | + |
| 78 | + export type StyledComponentProps< |
| 79 | + // The Component from whose props are derived |
| 80 | + C extends string | React.ComponentType<any>, |
| 81 | + // The Theme from the current context |
| 82 | + T extends object, |
| 83 | + // The other props added by the template |
| 84 | + O extends object, |
| 85 | + // The props that are made optional by .attrs |
| 86 | + A extends keyof any |
| 87 | + > = |
| 88 | + // Distribute O if O is a union type |
| 89 | + O extends object |
| 90 | + ? WithOptionalTheme< |
| 91 | + Omit< |
| 92 | + ReactDefaultizedProps< |
| 93 | + C, |
| 94 | + React.ComponentPropsWithRef< |
| 95 | + C extends IntrinsicElementsKeys | React.ComponentType<any> ? C : never |
| 96 | + > |
| 97 | + > & |
| 98 | + O, |
| 99 | + A |
| 100 | + > & |
| 101 | + Partial< |
| 102 | + Pick< |
| 103 | + React.ComponentPropsWithRef< |
| 104 | + C extends IntrinsicElementsKeys | React.ComponentType<any> ? C : never |
| 105 | + > & |
| 106 | + O, |
| 107 | + A |
| 108 | + > |
| 109 | + >, |
| 110 | + T |
| 111 | + > & |
| 112 | + WithChildrenIfReactComponentClass<C> |
| 113 | + : never; |
| 114 | + |
| 115 | + type Defaultize<P, D> = P extends any |
| 116 | + ? string extends keyof P |
| 117 | + ? P |
| 118 | + : Pick<P, Exclude<keyof P, keyof D>> & |
| 119 | + Partial<Pick<P, Extract<keyof P, keyof D>>> & |
| 120 | + Partial<Pick<D, Exclude<keyof D, keyof P>>> |
| 121 | + : never; |
| 122 | + |
| 123 | + type ReactDefaultizedProps<C, P> = C extends { defaultProps: infer D } ? Defaultize<P, D> : P; |
| 124 | + |
| 125 | + type WithChildrenIfReactComponentClass<C extends string | React.ComponentType<any>> = C extends React.ComponentClass< |
| 126 | + any |
| 127 | + > |
| 128 | + ? { children?: React.ReactNode } |
| 129 | + : {}; |
| 130 | + export type IntrinsicElementsKeys = keyof JSX.IntrinsicElements; |
| 131 | + type WithOptionalTheme<P extends { theme?: T }, T> = Omit<P, 'theme'> & { |
| 132 | + theme?: T; |
| 133 | + }; |
| 134 | + |
| 135 | + type ForwardRefExoticBase<P> = Pick<React.ForwardRefExoticComponent<P>, keyof React.ForwardRefExoticComponent<any>>; |
| 136 | + |
| 137 | + type StyledComponentPropsWithAs< |
| 138 | + C extends string | React.ComponentType<any>, |
| 139 | + T extends object, |
| 140 | + O extends object, |
| 141 | + A extends keyof any, |
| 142 | + F extends string | React.ComponentType<any> = C |
| 143 | + > = StyledComponentProps<C, T, O, A> & { as?: C; forwardedAs?: F }; |
| 144 | + |
| 145 | + export type StyledComponentInnerOtherProps<C extends AnyStyledComponent> = C extends StyledComponent< |
| 146 | + any, |
| 147 | + any, |
| 148 | + infer O, |
| 149 | + any |
| 150 | + > |
| 151 | + ? O |
| 152 | + : C extends StyledComponent<any, any, infer O> |
| 153 | + ? O |
| 154 | + : never; |
| 155 | + export type StyledComponentInnerAttrs<C extends AnyStyledComponent> = C extends StyledComponent<any, any, any, infer A> |
| 156 | + ? A |
| 157 | + : never; |
| 158 | + |
| 159 | + export interface StyledComponentBase< |
| 160 | + C extends string | React.ComponentType<any>, |
| 161 | + T extends object, |
| 162 | + O extends object = {}, |
| 163 | + A extends keyof any = never |
| 164 | + > extends ForwardRefExoticBase<StyledComponentProps<C, T, O, A>> { |
| 165 | + // add our own fake call signature to implement the polymorphic 'as' prop |
| 166 | + (props: StyledComponentProps<C, T, O, A> & { as?: never; forwardedAs?: never }): React.ReactElement< |
| 167 | + StyledComponentProps<C, T, O, A> |
| 168 | + >; |
| 169 | + <AsC extends string | React.ComponentType<any> = C, FAsC extends string | React.ComponentType<any> = AsC>( |
| 170 | + props: StyledComponentPropsWithAs<AsC, T, O, A, FAsC>, |
| 171 | + ): React.ReactElement<StyledComponentPropsWithAs<AsC, T, O, A, FAsC>>; |
| 172 | + |
| 173 | + withComponent<WithC extends AnyStyledComponent>( |
| 174 | + component: WithC, |
| 175 | + ): StyledComponent< |
| 176 | + ~~~~~~~~~~~~~~~~ |
| 177 | + StyledComponentInnerComponent<WithC>, |
| 178 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 179 | + T, |
| 180 | + ~~~~~~~~~~ |
| 181 | + O & StyledComponentInnerOtherProps<WithC>, |
| 182 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 183 | + A | StyledComponentInnerAttrs<WithC> |
| 184 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 185 | + >; |
| 186 | + ~~~~~ |
| 187 | +!!! error TS2615: Type of property 'propTypes' circularly references itself in mapped type 'ForwardRefExoticBase<Omit<Omit<any, any> & Partial<Pick<any, any>>, "theme"> & { theme?: any; } & WithChildrenIfReactComponentClass<StyledComponentInnerComponent<WithC>>>'. |
| 188 | + withComponent<WithC extends keyof JSX.IntrinsicElements | React.ComponentType<any>>( |
| 189 | + component: WithC, |
| 190 | + ): StyledComponent<WithC, T, O, A>; |
| 191 | + } |
| 192 | + |
| 193 | + export type StyledComponentInnerComponent<C extends React.ComponentType<any>> = C extends StyledComponent< |
| 194 | + infer I, |
| 195 | + any, |
| 196 | + any, |
| 197 | + any |
| 198 | + > |
| 199 | + ? I |
| 200 | + : C extends StyledComponent<infer I, any, any> |
| 201 | + ? I |
| 202 | + : C; |
| 203 | + export type StyledComponentPropsWithRef< |
| 204 | + C extends keyof JSX.IntrinsicElements | React.ComponentType<any> |
| 205 | + > = C extends AnyStyledComponent |
| 206 | + ? React.ComponentPropsWithRef<StyledComponentInnerComponent<C>> // shouldn't have an instantiation limit error |
| 207 | + : React.ComponentPropsWithRef<C>; |
0 commit comments