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
When I try to wrap custom React components with goober's "styled" method, TypeScript shows error im cases when component have required props.
import React from 'react'
import { styled } from 'goober'
interface IProps {
myProp: string
}
const Component: React.FC<IProps> = (props) => {
return <div>{props.myProp}</div>
}
const StyledComponent = styled(Component)``
/* Argument of type 'FC<IProps>' is not assignable to parameter of type 'Element | ElementClass'.
Type 'FunctionComponent<IProps>' is missing the following properties from type 'ElementClass': render, context, setState, forceUpdate, and 3 more. */
When I change myProp to optional, there is no errors.
@cristianbote yes, I think that JSX.Element, that used in this line of code describes type of Element like that:
<Component myProp={myProp} />
or
React.createElement(Component, { myProp })
When we provide our component as argument to styled method, they are not Element yet, so I think changing to JSX.FC will help. I can make PR next days, if you want :)
When I try to wrap custom React components with goober's "styled" method, TypeScript shows error im cases when component have required props.
When I change
myProp
to optional, there is no errors.TypeScript: 4.7.4
Goober: 2.1.10
Sandbox with problem's example: https://codesandbox.io/s/goober-typescript-styled-custom-component-y25bq0?file=/src/Component.tsx
The text was updated successfully, but these errors were encountered: