-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error trying to connect to typescript react component #13
Comments
Hi Phil, How is your React components are composed? There was another related issue here, the culprit was functional components. #10 Could you check it out if the solution I mentioned there works for you? If not, could you share a sample (anonymized if required) of your failed components? |
Hi, the code is below. Originally the top line was typescript: 3.7.2 We also use styled-components a lot so don't know if they are contributing to the problem `
}; |
@phil-armstrong where are you getting your types from? I had the same issue with my component, the solution was to put the type definition in the same file. import * as React from 'react'
import classnames from 'classnames'
import s from './Button.module.scss'
- import { IButtonType } from './Button.types'
+ export interface IButtonType {
+ onClick?: any
+ onMouseEnter?: any
+ onMouseLeave?: any
+ children: any
+ primary?: boolean
+ secondary?: boolean
+ tertiary?: boolean
+ icon?: boolean
+ attributes?: {}
+ large?: boolean
+ customClass?: string
+ testSelector?: string
+ name?: string
+ submitType?: boolean
+ disabled?: boolean
+ }
const Button = ({
attributes = {},
children,
customClass,
disabled,
icon,
large = false,
name,
onClick,
onMouseEnter,
onMouseLeave,
primary,
secondary,
submitType,
tertiary,
testSelector,
}: IButtonType) => (
<button
className={classnames(
{
[s.Primary]: primary,
[s.Secondary]: secondary,
[s.Tertiary]: tertiary,
[s.Icon]: icon,
[s.Large]: large,
[s.Disabled]: disabled,
},
customClass
)}
disabled={disabled}
data-testid={testSelector}
onClick={onClick}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
name={name}
type={submitType ? 'submit' : 'button'}
{...attributes}
>
{children}
</button>
)
export default Button However, I don't think it's great that same file typing is enforced, but I suppose that's an issue with react-docgen not being able to resolve imports rather than this plugin in particular. |
@jgarplind that appears to be the problem yes, moving the props into the same folder seems to have fixed the issue. Is there any suggestion from react-docgen that this issue will be fixed in the future? Edit: I had a look at react-docgen and they have had this pull request for a while but are still actively commenting on it, not sure if it'll be merged |
Yes Phil, I am also waiting for that PR to be merged 😅 We may create hack build or a custom resolver built on the PR but comments mention some stability issues, it is best to wait a bit more. |
Closing as it won't be fixed as part of this repository. Waiting reactjs/react-docgen#352 to be merged. |
You can now set an option to use react-docgen-typescript for TS files. It will handle imported props. |
Hi,
I was playing around with the new component features and got the following error from 'zeplin connect --dev'
My react component is written in react and has a couple of props that are optional (i.e. color?: string) so I think it's probably related to that but not too sure.
Thanks
`Connecting components to Zeplin components failed.
`
The text was updated successfully, but these errors were encountered: