Skip to content
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

withProps typings issues #5

Open
mathieutu opened this issue Aug 5, 2019 · 2 comments
Open

withProps typings issues #5

mathieutu opened this issue Aug 5, 2019 · 2 comments
Labels
bug Something isn't working react-with-props

Comments

@mathieutu
Copy link

Hi,
thank's for this package.

I have an issue with withProps typing.

I have this piece of code:

const UnstyledLabel = withProps(
  ({ error = false }: { error: boolean }) => ({ 
	variant: error ? 't12' : 't8',
	as: 'label' 
  }),
  Typography,
)

where I'm trying to set props on Typography component, depending of an error props of an UnstyledLabel.

Here, all type are passed, and should be properly inferred, but I'm getting this error:

Error:(12, 3) TS2345: Argument of type '({ error }: { error: boolean; }) => { variant: string; as: string; }' is not assignable to parameter of type '{ variant: string; as: string; } | Injector<{ error: boolean; }, { variant: string; as: string; }>'.
  Type '({ error }: { error: boolean; }) => { variant: string; as: string; }' is not assignable to type 'Injector<{ error: boolean; }, { variant: string; as: string; }>'.
    Types of parameters '__0' and 'props' are incompatible.
      Type '{ error: boolean; } | undefined' is not assignable to type '{ error: boolean; }'.
        Type 'undefined' is not assignable to type '{ error: boolean; }'.

For me it's because of the ? in react-with-props/src/index.ts:12:
type Injector<Props, InjectedProps> = (props?: Props) => InjectedProps.

How can I solve my problem?

Thanks.
Matt'

@goblindegook
Copy link
Member

Hi @mathieutu, I'd like to reproduce your issue, could you let me know which version of TypeScript you're using and what package (and package version) Typography belongs to?

Thanks for reporting it!

@goblindegook goblindegook added bug Something isn't working react-with-props labels Aug 14, 2019
@mathieutu
Copy link
Author

Typography is a basic component on my own which accept variant and as as props. And here the problem doesn't come from the passed component but from the injected props. (See my code ref, which provoke the undefined)

I'm on the last version of typescript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working react-with-props
Projects
None yet
Development

No branches or pull requests

2 participants