Open amcasey opened 4 years ago
Any update here? π€
Having the same issue using Styled Components with React and TypeScript 3.9.2
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 π
Try to use
export const EditableAuthorTag = styled(AuthorTag as any)
Try to use
export const EditableAuthorTag = styled(AuthorTag as any)
Thank you, it worked for me.
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 https://github.com/microsoft/TypeScript/pull/36696).
This breaking change was mitigated by updating @types/styled-components
https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42619
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 https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42619 e.g.:
= P & ThemeProps = ThemedStyledProps >;
// 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 unions
type Defaultize = P extends any
? string extends keyof P ? P :
& Pick >
& Partial
: P;
export type StyledComponentProps<
// The Component from whose props are derived
C extends keyof JSX.IntrinsicElements | React.ComponentType =
| InterpolationValue
| InterpolationFunction
| FlattenInterpolation ;
// cannot be made a self-referential interface, breaks WithPropNested
// see https://github.com/microsoft/TypeScript/issues/34796
export type FlattenInterpolation = ReadonlyArray = (props: P) => Interpolation ;
type Attrs , T> =
| ((props: ThemedStyledProps ) => A)
| A;
type DeprecatedAttrs , T> = {
[K in keyof A]: ((props: ThemedStyledProps ) => A[K]) | A[K]
};
export type ThemedGlobalStyledClassProps = WithOptionalTheme & {
suppressMultiMountWarning?: boolean;
};
export interface GlobalStyleComponent
extends React.ComponentClass = Pick<
React.ForwardRefExoticComponent ,
keyof React.ForwardRefExoticComponent (
first:
| TemplateStringsArray
| CSSObject
| InterpolationFunction = Omit & {
theme?: T;
};
type AnyIfEmpty (
first:
| TemplateStringsArray
| CSSObject
| InterpolationFunction ;
withTheme: WithThemeFnInterface (
first:
| TemplateStringsArray
| CSSObject
| InterpolationFunction ;
export function isStyledComponent(
target: any
): target is StyledComponent
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 π
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-components
DefinitelyTyped/DefinitelyTyped#42619However, this fix was deployed at
v5.0.1
of@types/styled-components
which coversstyled-components@^5.0.0
but, nothing has been deployed for earlier versions (e.g. what would coverstyled-components@^4.0.0
)So if you are using
styled-components@^5.0.0
simply runyarn 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, copystyled-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 π
Upgrading the types worked for me. Thank you! π
Still happening for me.. :'( I'm similarly trying to extend a component like follows:
Type of property 'defaultProps' circularly references itself in mapped type 'Pick<ForwardRefExoticComponent<Pick<Pick<any, Exclude<keyof ReactDefaultizedProps<StyledComponentInnerComponent<WithC>, ComponentPropsWithRef<StyledComponentInnerComponent<WithC>>>, any>> & Partial<...>, any> & { ...; } & WithChildrenIfReactComponentClass<...>>, "defaultProps" | ... 2 more ... | "$$typeof">'. TS2615
28 | `;
29 |
> 30 | export const PrimaryButton = styled(Button)`
| ^
31 | background-color: ${props => props.theme.primaryColor};
32 | border: none;
33 | color: ${props => props.theme.textColorOnPrimary};
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",
Still happening for me.. :'( I'm similarly trying to extend a component like follows:
Type of property 'defaultProps' circularly references itself in mapped type 'Pick<ForwardRefExoticComponent<Pick<Pick<any, Exclude<keyof ReactDefaultizedProps<StyledComponentInnerComponent<WithC>, ComponentPropsWithRef<StyledComponentInnerComponent<WithC>>>, any>> & Partial<...>, any> & { ...; } & WithChildrenIfReactComponentClass<...>>, "defaultProps" | ... 2 more ... | "$$typeof">'. TS2615 28 | `; 29 | > 30 | export const PrimaryButton = styled(Button)` | ^ 31 | background-color: ${props => props.theme.primaryColor}; 32 | border: none; 33 | color: ${props => props.theme.textColorOnPrimary};
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",
Try removing the ^
from your typescript version to make sure it is actually 3.6.5 and not a higher version
EDIT: I bumped my typescript version to 3.8.3 and afterwards it compiled just fine
For me this issue was caused by my IDE (VSCode) using a new version of Typescript (3.9.4) to check typings against an old version of Styled Components (4.3.1).
While upgrading both Typescript and Styled Components to the latest versions is probably the best solution, a quick fix that worked for me was to tell VSCode to use the workspace version of Typescript (3.7.5) instead of the latest version.
For me this issue was caused by my IDE (VSCode) using a new version of Typescript (3.9.4) to check typings against an old version of Styled Components (4.3.1).
While upgrading both Typescript and Styled Components to the latest versions is probably the best solution, a quick fix that worked for me was to tell VSCode to use the workspace version of Typescript (3.7.5) instead of the latest version.
would be nice to know where you would configure this @Oulander
would be nice to know where you would configure this @Oulander
@jermainedebruyne In VSCode you can find the version picker either by clicking the version number on the right side of the status bar at the bottom edge of the window, or by using the command palette (see pic). From there, choose "Use Workspace Version" instead of "Use VS Code's Version".
would be nice to know where you would configure this @Oulander
@jermainedebruyne In VSCode you can find the version picker either by clicking the version number on the right side of the status bar at the bottom edge of the window, or by using the command palette (see pic). From there, choose "Use Workspace Version" instead of "Use VS Code's Version".
Thanks! My problem was that I had 1 VSCode window for multiple repos. Then the version is not simply in the root of one project. Therefore I had to switch to multiple VSCode windows... Not optimal.. I also applied your suggestion π
This breaking change was mitigated by updating
@types/styled-components
DefinitelyTyped/DefinitelyTyped#42619 So if you are usingstyled-components@^5.0.0
simply run npm install @types/styled-components@latest
We didn't have styled-components installed in our project, yet this gave me the idea of updating the similar @types/ packages we are using, and this worked, so thank you. Updating @types/vuelidate to the latest version (0.7.13) fixed it for me, and this is on the latest version of Typescript (3.9.6).
Letting others know that it may not specifically be one of these packages that is giving their error, but possibly some other type-related package, so it's worth experimenting.
I don't know if it's the same error, but we're having similar sudden circular reference issues in Vue props after trying to upgrade from 3.8.3 to something higher. I bisected all of the releases > 3.8.3 and we tracked down the exact version that breaks: 3.9.0-dev.20200228 (works) -> 3.9.0-dev.20200229 (breaks). These don't seem to be tagged in git so I'm not sure where they come from to compare them.
I wonder if anyone else having this problem can check if these two versions are where your breaking change happened?
If this helps anyone I identified that my problem was using styled-components-modifiers
which called applyStyleModifiers
inside the css
prop. Removing this got rid of the problem for me.
Not sure if anyone else is going to make the same mistake as me, but for me the error was caused by the fact that I missed the return statement in the wrapped component. So, instead of
return (
<div />
)
I just had
<div />
Updating typescript
and @types/styled-components
to the latest version solved the issue for me
This problem still exist when some interface extends Document
from mongoose
library, I am on typescript@4.1.3
and mongoose@5.11.11
I have my interface defined like this
import { Document } from 'mongoose';
interface A extends Document {
someProperty: A,
...
}
And then, error is looking like
Type of property 'someProperty' circularly references itself in mapped type
@weswigham / @RyanCavanaugh we're not sure if this is a different issue, but if you need a non-styled-components use case / reproduction for "circularly references itself in mapped type" errors, we have this PR on our open source project:
https://github.com/stephenh/joist-ts/pull/127
That with ~a few lines of change creates errors like:
packages/integration-tests/src/entities/AuthorCodegen.ts:124:29 - error TS2615: Type of property 'book' circularly references itself in mapped type '{ fileName: "fileName"; type: "type"; author: "author"; book: "book"; publisher: "publisher"; }'.
124 export const authorConfig = new ConfigApi<Author, Context>();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
packages/integration-tests/src/entities/AuthorCodegen.ts:124:29 - error TS2615: Type of property 'book' circularly references itself in mapped type '{ fileName: FieldStatus<string>; type: FieldStatus<ImageType.BookImage> | FieldStatus<ImageType.AuthorImage> | FieldStatus<ImageType.PublisherImage>; author: FieldStatus<...>; book: FieldStatus<...>; publisher: FieldStatus<...>; }'.
124 export const authorConfig = new ConfigApi<Author, Context>();
Understood that isn't as good as a ~10 line standalone repro, but it's what we've got so far... :-/
This "circular references" error has hit us ~2-3 times on changes we've tried to make recently, and we're really not sure how to approach debugging what the cause it or how to fix/avoid it.
We're pretty sure this stems from this Loaded
mapped type:
https://github.com/stephenh/joist-ts/blob/main/packages/orm/src/EntityManager.ts#L155
Which lets us make "hint-driven" projections of our entity graph (basically turning tedious/boilerpately "must be async" accesses into "just call .get
sync", and given the connectedness of the entity graph (i.e. an author points to the book and the book points to the author), we assume that this is what sends the TS compiler down a rabbit hole of recursion/something/something/we really don't know.
Same issue is happening on all imports from chakra-ui
. Basically impossible to use without ts-ignoring
every single instance of a component.
../../packages/titan-chakra/src/components/Text.tsx:5:10 - error TS2615: Type of property 'defaultProps' circularly references itself in mapped type 'ForwardRefExoticBase<Omit<Omit<any, any> & Partial<Pick<any, any>>, "theme"> & { theme?: any; } & WithChildrenIfReactComponentClass<StyledComponentInnerComponent<WithC>>>'.
5 return <Text fontSize="sm">hello</Text>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Any guidance?
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
Issue still persist in version 4.6.2
@RyanCavanaugh
https://github.com/nteract/nteract/blob/af734c46893146c617308f4ae1e40bf267e8875f/packages/connected-components/src/header-editor/styled.ts#L24
https://github.com/nteract/nteract/blob/af734c46893146c617308f4ae1e40bf267e8875f/packages/presentational-components/src/components/prompt.tsx#L85
Also, I'm seeing each of these errors printed twice.
To repro: 1)
yarn
2)tsc -b -f
Note that it fails with a different (apparently unrelated) error in 3.8.