You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New error: Type of property 'defaultProps' circularly references itself in mapped type #37597
I'm having this issue aswell. It turns out that something has fucked up with the latest (or one of the latest) release(-s).
I managed to resolve this temporarily by simply downgrading TS version to 3.6.5
npm i -D typescript@3.6.5
Should solve the issue 😄
Reacted by Carol Hu, Ramakrishna Chilaka, Serhii Tatsiak, Liudas, Craig Sketchley, Slav Dachev, wackerow, Gauri Shankar Badola and Alejandro Zapeta
Reacted by Chintu Mohandas, Julien Barbé, 张帅, synnestenvold, medik, AlphaGolf33, Enix, Matt Greer, NenadJovicic, Hen Greville and 5 more
export const EditableAuthorTag = styled(AuthorTag as any)
Reacted by Jaqueline Kimmi Kirino, Max Tuzzolino, AlgoTrader, David, victornerit, Amecy, Matěj Podzemný, Jesus Padron, Roberto Martins da Silva, Derrick Franco and 23 more
Reacted by Lukas Klusis, Chintu Mohandas, Tony Gentilcore, Dmitriy Tupalov, Kağan Küçük, Liudas, Oliver Benns, Ayoub Aabass, Joe McKie, SesH92 and 70 more
Reacted by Joshua Wootonn, Liudas, Ville Vainio, Regis/레지스, Derrick Franco, Julián Alazorza, Deniz Bilgin, LevonHaroutyunyan, kazusa, Renan Maciel and 5 more
Reacted by LevonHaroutyunyan, Jefferson Martins de Andrade, Omer Aplak, Alonso ZB and Jean Karlo Obando Ramos
export const EditableAuthorTag = styled(AuthorTag as any)
Thank you, it worked for me.
Reacted by Tim Bright, Derrick Franco, Fernando R., Jack Lyons, wjxalexander, Jefferson Martins de Andrade, Alejandro Zapeta, Stephen Algeo, Thomas Gak-Deluen and Mehran
Reacted by Artem Sapegin, e00dan, Tolga, Craig Sketchley, Jay Puntham-Baker, Tony Gentilcore, Sumin Lim, Derrick Franco, Ing. Lukáš Frantál, Deniz Bilgin and 30 more
However, this fix was deployed at v5.0.1 of @types/styled-components which covers styled-components@^5.0.0
but, nothing has been deployed for earlier versions (e.g. what would cover styled-components@^4.0.0)
So if you are using styled-components@^5.0.0 simply run
yarn upgrade @types/styled-components --latest
# or
npm install @types/styled-components@latest
if you are using styled-components@^4.0.0, well then it is more difficult for now, as in essence @types/styled-components should be updated.
However, as a temporary fix it is possible to remove @types/styled-components from the project, copy styled-components.d.ts file from @types/styled-components@^4.0.0 to your project and make the same fix as in DefinitelyTyped/DefinitelyTyped#42619 e.g.:
example content of styled-components.d.ts
// forward declarationsdeclare global {namespaceNodeJS{// tslint:disable-next-line:no-empty-interfaceinterfaceReadableStream{}}}declare module 'styled-components'{import*asCSSfrom"csstype";import*asReactfrom"react";import*ashoistNonReactStaticsfrom'hoist-non-react-statics';exporttypeCSSProperties=CSS.Properties<string|number>;exporttypeCSSPseudos={[KinCSS.Pseudos]?: CSSObject};exportinterfaceCSSObjectextendsCSSProperties,CSSPseudos{[key: string]: CSSObject|string|number|undefined;}exporttypeCSSKeyframes=object&{[key: string]: CSSObject};exportinterfaceThemeProps<T>{theme: T;}exporttypeThemedStyledProps<P,T>=P&ThemeProps<T>;exporttypeStyledProps<P>=ThemedStyledProps<P,AnyIfEmpty<DefaultTheme>>;// Any prop that has a default prop becomes optional, but its type is unchanged// Undeclared default props are augmented into the resulting allowable attributes// If declared props have indexed properties, ignore default props entirely as keyof gets widened// Wrap in an outer-level conditional type to allow distribution over props that are unionstypeDefaultize<P,D>=Pextendsany
? stringextendskeyofP ? P :
&Pick<P,Exclude<keyofP,keyofD>>&Partial<Pick<P,Extract<keyofP,keyofD>>>&Partial<Pick<D,Exclude<keyofD,keyofP>>>
: never;typeReactDefaultizedProps<C,P>=Cextends{defaultProps: infer D;}
? Defaultize<P,D>
: P;exporttypeStyledComponentProps<// The Component from whose props are derivedCextendskeyofJSX.IntrinsicElements|React.ComponentType<any>,// The Theme from the current contextTextendsobject,// The other props added by the templateOextendsobject,// The props that are made optional by .attrsAextendskeyofany>=// Distribute O if O is a union typeOextendsobject
? WithOptionalTheme<Omit<ReactDefaultizedProps<C,React.ComponentPropsWithRef<C>>&O,A>&Partial<Pick<React.ComponentPropsWithRef<C>&O,A>>,T>&WithChildrenIfReactComponentClass<C>
: never;// Because of React typing quirks, when getting props from a React.ComponentClass,// we need to manually add a `children` field.// See https://github.com/DefinitelyTyped/DefinitelyTyped/pull/31945// and https://github.com/DefinitelyTyped/DefinitelyTyped/pull/32843typeWithChildrenIfReactComponentClass<CextendskeyofJSX.IntrinsicElements|React.ComponentType<any>>=CextendsReact.ComponentClass<any> ? {children?: React.ReactNode} : {};typeStyledComponentPropsWithAs<CextendskeyofJSX.IntrinsicElements|React.ComponentType<any>,Textendsobject,Oextendsobject,Aextendskeyofany>=StyledComponentProps<C,T,O,A>&{as?: C,forwardedAs?: C};exporttypeFalseyValue=undefined|null|false;exporttypeInterpolation<P>=|InterpolationValue|InterpolationFunction<P>|FlattenInterpolation<P>;// cannot be made a self-referential interface, breaks WithPropNested// see https://github.com/microsoft/TypeScript/issues/34796exporttypeFlattenInterpolation<P>=ReadonlyArray<Interpolation<P>>;exporttypeInterpolationValue=|string|number|FalseyValue|Keyframes|StyledComponentInterpolation|CSSObject;exporttypeSimpleInterpolation=|InterpolationValue|FlattenSimpleInterpolation;exporttypeFlattenSimpleInterpolation=ReadonlyArray<SimpleInterpolation>;exporttypeInterpolationFunction<P>=(props: P)=>Interpolation<P>;typeAttrs<P,AextendsPartial<P>,T>=|((props: ThemedStyledProps<P,T>)=>A)|A;typeDeprecatedAttrs<P,AextendsPartial<P>,T>={[KinkeyofA]: ((props: ThemedStyledProps<P,T>)=>A[K])|A[K]};exporttypeThemedGlobalStyledClassProps<P,T>=WithOptionalTheme<P,T>&{suppressMultiMountWarning?: boolean;};exportinterfaceGlobalStyleComponent<P,T>extendsReact.ComponentClass<ThemedGlobalStyledClassProps<P,T>>{}// remove the call signature from StyledComponent so Interpolation can still infer InterpolationFunctiontypeStyledComponentInterpolation=|Pick<StyledComponentBase<any,any,any,any>,keyofStyledComponentBase<any,any>>|Pick<StyledComponentBase<any,any,any>,keyofStyledComponentBase<any,any>>;// abuse Pick to strip the call signature from ForwardRefExoticComponenttypeForwardRefExoticBase<P>=Pick<React.ForwardRefExoticComponent<P>,keyofReact.ForwardRefExoticComponent<any>>;// extracts React defaultPropstypeReactDefaultProps<C>=Cextends{defaultProps: infer D;} ? D : never;// any doesn't count as assignable to never in the extends clause, and we default A to neverexporttypeAnyStyledComponent=|StyledComponent<any,any,any,any>|StyledComponent<any,any,any>;exporttypeStyledComponent<CextendskeyofJSX.IntrinsicElements|React.ComponentType<any>,Textendsobject,Oextendsobject={},Aextendskeyofany=never>=// the "string" allows this to be used as an object key// I really want to avoid this if possible but it's the only way to use nesting with object styles...string&StyledComponentBase<C,T,O,A>&hoistNonReactStatics.NonReactStatics<CextendsReact.ComponentType<any> ? C : never>;exportinterfaceStyledComponentBase<CextendskeyofJSX.IntrinsicElements|React.ComponentType<any>,Textendsobject,Oextendsobject={},Aextendskeyofany=never>extendsForwardRefExoticBase<StyledComponentProps<C,T,O,A>>{// add our own fake call signature to implement the polymorphic 'as' prop(props: StyledComponentProps<C,T,O,A>&{as?: never,forwardedAs?: never}): React.ReactElement<StyledComponentProps<C,T,O,A>>;<AsCextendskeyofJSX.IntrinsicElements|React.ComponentType<any>=C>(props: StyledComponentPropsWithAs<AsC,T,O,A>): React.ReactElement<StyledComponentPropsWithAs<AsC,T,O,A>>;withComponent<WithCextendsAnyStyledComponent>(component: WithC): StyledComponent<StyledComponentInnerComponent<WithC>,T,O&StyledComponentInnerOtherProps<WithC>,A|StyledComponentInnerAttrs<WithC>>;withComponent<WithCextendskeyofJSX.IntrinsicElements|React.ComponentType<any>>(component: WithC): StyledComponent<WithC,T,O,A>;}exportinterfaceThemedStyledFunctionBase<CextendskeyofJSX.IntrinsicElements|React.ComponentType<any>,Textendsobject,Oextendsobject={},Aextendskeyofany=never>{(first: TemplateStringsArray): StyledComponent<C,T,O,A>;(first:
|TemplateStringsArray|CSSObject|InterpolationFunction<ThemedStyledProps<StyledComponentPropsWithRef<C>&O,T>>,
...rest: Array<Interpolation<ThemedStyledProps<StyledComponentPropsWithRef<C>&O,T>>>): StyledComponent<C,T,O,A>;<Uextendsobject>(first:
|TemplateStringsArray|CSSObject|InterpolationFunction<ThemedStyledProps<StyledComponentPropsWithRef<C>&O&U,T>>,
...rest: Array<Interpolation<ThemedStyledProps<StyledComponentPropsWithRef<C>&O&U,T>>>): StyledComponent<C,T,O&U,A>;}exportinterfaceThemedStyledFunction<CextendskeyofJSX.IntrinsicElements|React.ComponentType<any>,Textendsobject,Oextendsobject={},Aextendskeyofany=never>extendsThemedStyledFunctionBase<C,T,O,A>{// Fun thing: 'attrs' can also provide a polymorphic 'as' prop// My head already hurts enough so maybe later...attrs<U,NewAextendsPartial<StyledComponentPropsWithRef<C>&U>&{[others: string]: any;}={}>(attrs: Attrs<StyledComponentPropsWithRef<C>&U,NewA,T>): ThemedStyledFunction<C,T,O&NewA,A|keyofNewA>;// Only this overload is deprecated// tslint:disable:unified-signatures/** @deprecated Prefer using the new single function style, to be removed in v5 */attrs<U,NewAextendsPartial<StyledComponentPropsWithRef<C>&U>&{[others: string]: any;}={}>(attrs: DeprecatedAttrs<StyledComponentPropsWithRef<C>&U,NewA,T>): ThemedStyledFunction<C,T,O&NewA,A|keyofNewA>;// tslint:enable:unified-signatures}exporttypeStyledFunction<CextendskeyofJSX.IntrinsicElements|React.ComponentType<any>>=ThemedStyledFunction<C,any>;typeThemedStyledComponentFactories<Textendsobject>={[TTaginkeyofJSX.IntrinsicElements]: ThemedStyledFunction<TTag,T>};exporttypeStyledComponentInnerComponent<CextendsReact.ComponentType<any>>=CextendsStyledComponent<infer I,any,any,any> ? I :
CextendsStyledComponent<infer I,any,any> ? I :
C;exporttypeStyledComponentPropsWithRef<CextendskeyofJSX.IntrinsicElements|React.ComponentType<any>>=CextendsAnyStyledComponent
? React.ComponentPropsWithRef<StyledComponentInnerComponent<C>>
: React.ComponentPropsWithRef<C>;exporttypeStyledComponentInnerOtherProps<CextendsAnyStyledComponent>=CextendsStyledComponent<any,any, infer O,any> ? O :
CextendsStyledComponent<any,any, infer O> ? O :
never;exporttypeStyledComponentInnerAttrs<CextendsAnyStyledComponent>=CextendsStyledComponent<any,any,any, infer A> ? A : never;exportinterfaceThemedBaseStyledInterface<Textendsobject>extendsThemedStyledComponentFactories<T>{<CextendsAnyStyledComponent>(component: C): ThemedStyledFunction<StyledComponentInnerComponent<C>,T,StyledComponentInnerOtherProps<C>,StyledComponentInnerAttrs<C>>;<CextendskeyofJSX.IntrinsicElements|React.ComponentType<any>>(// unfortunately using a conditional type to validate that it can receive a `theme?: Theme`// causes tests to fail in TS 3.1component: C): ThemedStyledFunction<C,T>;}exporttypeThemedStyledInterface<Textendsobject>=ThemedBaseStyledInterface<AnyIfEmpty<T>>;exporttypeStyledInterface=ThemedStyledInterface<DefaultTheme>;exportinterfaceBaseThemedCssFunction<Textendsobject>{(first: TemplateStringsArray|CSSObject,
...interpolations: SimpleInterpolation[]): FlattenSimpleInterpolation;(first:
|TemplateStringsArray|CSSObject|InterpolationFunction<ThemedStyledProps<{},T>>,
...interpolations: Array<Interpolation<ThemedStyledProps<{},T>>>): FlattenInterpolation<ThemedStyledProps<{},T>>;<Pextendsobject>(first:
|TemplateStringsArray|CSSObject|InterpolationFunction<ThemedStyledProps<P,T>>,
...interpolations: Array<Interpolation<ThemedStyledProps<P,T>>>): FlattenInterpolation<ThemedStyledProps<P,T>>;}exporttypeThemedCssFunction<Textendsobject>=BaseThemedCssFunction<AnyIfEmpty<T>>;// Helper type operatorstypeOmit<T,KextendskeyofT>=Pick<T,Exclude<keyofT,K>>;typeWithOptionalTheme<Pextends{theme?: T},T>=Omit<P,"theme">&{theme?: T;};typeAnyIfEmpty<Textendsobject>=keyofTextendsnever ? any : T;exportinterfaceThemedStyledComponentsModule<Textendsobject,Uextendsobject=T>{default: ThemedStyledInterface<T>;css: ThemedCssFunction<T>;// unfortunately keyframes can't interpolate props from the themekeyframes(strings: TemplateStringsArray|CSSKeyframes,
...interpolations: SimpleInterpolation[]): Keyframes;createGlobalStyle<Pextendsobject={}>(first:
|TemplateStringsArray|CSSObject|InterpolationFunction<ThemedStyledProps<P,T>>,
...interpolations: Array<Interpolation<ThemedStyledProps<P,T>>>): GlobalStyleComponent<P,T>;withTheme: WithThemeFnInterface<T>;ThemeProvider: ThemeProviderComponent<T,U>;ThemeConsumer: React.Consumer<T>;ThemeContext: React.Context<T>;// This could be made to assert `target is StyledComponent<any, T>` instead, but that feels not type safeisStyledComponent: typeofisStyledComponent;ServerStyleSheet: typeofServerStyleSheet;StyleSheetManager: typeofStyleSheetManager;}declareconststyled: StyledInterface;exportconstcss: ThemedCssFunction<DefaultTheme>;exporttypeBaseWithThemeFnInterface<Textendsobject>=<CextendsReact.ComponentType<any>>(// this check is roundabout because the extends clause above would// not allow any component that accepts _more_ than theme as a propcomponent: React.ComponentProps<C>extends{theme?: T} ? C : never)=>React.ForwardRefExoticComponent<WithOptionalTheme<React.ComponentPropsWithRef<C>,T>>;exporttypeWithThemeFnInterface<Textendsobject>=BaseWithThemeFnInterface<AnyIfEmpty<T>>;exportconstwithTheme: WithThemeFnInterface<DefaultTheme>;/** * This interface can be augmented by users to add types to `styled-components`' default theme * without needing to reexport `ThemedStyledComponentsModule`. */// Unfortunately, there is no way to write tests for this// as any augmentation will break the tests for the default case (not augmented).// tslint:disable-next-line:no-empty-interfaceexportinterfaceDefaultTheme{}exportinterfaceThemeProviderProps<Textendsobject,Uextendsobject=T>{children?: React.ReactNode;theme: T|((theme: U)=>T);}exporttypeBaseThemeProviderComponent<Textendsobject,Uextendsobject=T>=React.ComponentClass<ThemeProviderProps<T,U>>;exporttypeThemeProviderComponent<Textendsobject,Uextendsobject=T>=BaseThemeProviderComponent<AnyIfEmpty<T>,AnyIfEmpty<U>>;exportconstThemeProvider: ThemeProviderComponent<AnyIfEmpty<DefaultTheme>>;// NOTE: this technically starts as undefined, but allowing undefined is unhelpful when used correctlyexportconstThemeContext: React.Context<AnyIfEmpty<DefaultTheme>>;exportconstThemeConsumer: typeofThemeContext["Consumer"];exportinterfaceKeyframes{getName(): string;}exportfunctionkeyframes(strings: TemplateStringsArray|CSSKeyframes,
...interpolations: SimpleInterpolation[]): Keyframes;exportfunctioncreateGlobalStyle<Pextendsobject={}>(first:
|TemplateStringsArray|CSSObject|InterpolationFunction<ThemedStyledProps<P,DefaultTheme>>,
...interpolations: Array<Interpolation<ThemedStyledProps<P,DefaultTheme>>>): GlobalStyleComponent<P,DefaultTheme>;exportfunctionisStyledComponent(target: any): target is StyledComponent<any,any>;exportclassServerStyleSheet{collectStyles(tree: React.ReactNode): React.ReactElement<{sheet: ServerStyleSheet}>;getStyleTags(): string;getStyleElement(): Array<React.ReactElement<{}>>;interleaveWithNodeStream(readableStream: NodeJS.ReadableStream): NodeJS.ReadableStream;readonlyinstance: this;seal(): void;}typeStyleSheetManagerProps=|{sheet: ServerStyleSheet;target?: never;}|{sheet?: never;target: HTMLElement;};exportclassStyleSheetManagerextendsReact.Component<StyleSheetManagerProps>{}/** * The CSS prop is not declared by default in the types as it would cause 'css' to be present * on the types of anything that uses styled-components indirectly, even if they do not use the * babel plugin. * * You can load a default declaration by using writing this special import from * a typescript file. This module does not exist in reality, which is why the {} is important: * * ```ts * import {} from 'styled-components/cssprop' * ``` * * Or you can declare your own module augmentation, which allows you to specify the type of Theme: * * ```ts * import { CSSProp } from 'styled-components' * * interface MyTheme {} * * declare module 'react' { * interface Attributes { * css?: CSSProp<MyTheme> * } * } * ``` */// ONLY string literals and inline invocations of css`` are supported, anything else crashes the pluginexporttypeCSSProp<T=AnyIfEmpty<DefaultTheme>>=|string|CSSObject|FlattenInterpolation<ThemeProps<T>>;exportdefaultstyled;}
and sorry that I'm posting this still on TypeScript repository, where it seems that DefinitelyTyped repository would be a better fit for this issue 😅
Reacted by Chintu Mohandas, Luiz Carlos W dos Santos, Mr.zhao, Nima, Jeroen de Jong, Jack Weeden, Mathieu Doyon, Robbie Ostrow, Boonyarith Piriyothinkul, Alessandro Dolci and 131 more
Reacted by Aakash, Eyden Villanueva and Osku
Reacted by Chintu Mohandas, Luke Ramus, Vinícius Pacheco Vieira, Justin Lawson, Adam Knee, G. Herzog, henry, Marcelo Cardoso, Ahmed Ashraf, DaBin (Rupa) and 32 more
Reacted by Sebastian
Reacted by Irving Armenta, Vinícius Pacheco Vieira, Belal Al Mazlom, Justin Lawson, Adam Knee, henry, Andrew Ribeiro, SunJin Choi, Nadiia Ridko, DaBin (Rupa) and 27 more
Reacted by DaBin (Rupa), André Almeida, Dmitry Minkovsky, 张帅, 陈海锦, Alexandra Duval, Felipe Developer, dj, yunlonglee, Zick and 11 more
However, this fix was deployed at v5.0.1 of @types/styled-components which covers styled-components@^5.0.0
but, nothing has been deployed for earlier versions (e.g. what would cover styled-components@^4.0.0)
So if you are using styled-components@^5.0.0 simply run
yarn upgrade @types/styled-components --latest
# or
npm install @types/styled-components@latest
if you are using styled-components@^4.0.0, well then it is more difficult for now, as in essence @types/styled-components should be updated.
However, as a temporary fix it is possible to remove @types/styled-components from the project, copy styled-components.d.ts file from @types/styled-components@^4.0.0 to your project and make the same fix as in DefinitelyTyped/DefinitelyTyped#42619 e.g.:
example content of styled-components.d.ts
and sorry that I'm posting this still on TypeScript repository, where it seems that DefinitelyTyped repository would be a better fit for this issue 😅
seems to be buried in the mongoose generics defs
those signatures appear to be klomped on klomp over time
its a matter if reworking your generics <T>
and constraint <T extends {id: Types.ObjectId | string | number}>
generics signatures
and actual call signatures
I could be wrong but thats where I am at modeling my own custom DIY repositories for back end entity mgt
Activity
chin2km commentedon May 13, 2020
Any update here? 🤔
loolooii commentedon May 13, 2020
Having the same issue using Styled Components with React and TypeScript 3.9.2
theLiudas commentedon May 13, 2020
I'm having this issue aswell. It turns out that something has fucked up with the latest (or one of the latest) release(-s).
I managed to resolve this temporarily by simply downgrading TS version to 3.6.5
Should solve the issue 😄
VladKabantsov commentedon May 13, 2020
Try to use
kimmikirino commentedon May 13, 2020
Thank you, it worked for me.
lukaskl commentedon May 13, 2020
Not sure if that applies for all of us, but it seems that this error appears using
typescript@^3.9.0(particularly after this PR #36696).This breaking change was mitigated by updating
@types/styled-componentsDefinitelyTyped/DefinitelyTyped#42619However, this fix was deployed at
v5.0.1of@types/styled-componentswhich coversstyled-components@^5.0.0but, nothing has been deployed for earlier versions (e.g. what would cover
styled-components@^4.0.0)So if you are using
styled-components@^5.0.0simply runif you are using
styled-components@^4.0.0, well then it is more difficult for now, as in essence@types/styled-componentsshould be updated.However, as a temporary fix it is possible to remove
@types/styled-componentsfrom the project, copystyled-components.d.tsfile from@types/styled-components@^4.0.0to your project and make the same fix as in DefinitelyTyped/DefinitelyTyped#42619 e.g.:example content of styled-components.d.ts
and sorry that I'm posting this still on TypeScript repository, where it seems that DefinitelyTyped repository would be a better fit for this issue 😅
AdamAnSubtractM commentedon May 22, 2020
Upgrading the types worked for me. Thank you! 🙏
sopianguyen commentedon Jun 2, 2020
Still happening for me.. :'( I'm similarly trying to extend a component like follows:
My relevant packages are
"typescript": "^3.6.5",
"styled-components": "^5.1.1",
"@types/styled-components": "^5.1.0",
"@typescript-eslint/eslint-plugin": "^3.1.0",
"@typescript-eslint/parser": "^3.1.0",
34 remaining items
nhhockeyplayer commentedon Dec 21, 2021
seems to be buried in the mongoose generics defs
those signatures appear to be klomped on klomp over time
its a matter if reworking your generics
<T>and constraint
<T extends {id: Types.ObjectId | string | number}>generics signatures
and actual call signatures
I could be wrong but thats where I am at modeling my own custom DIY repositories for back end entity mgt
Tomas2D commentedon Mar 14, 2022
Issue still persist in version
4.6.2Ryan Cavanaugh (@RyanCavanaugh)remove modal radius on mobile (#1108)