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

Array prop with a union type including undefined causes an error #36

Open
samtjo opened this issue Apr 25, 2022 · 0 comments
Open

Array prop with a union type including undefined causes an error #36

samtjo opened this issue Apr 25, 2022 · 0 comments

Comments

@samtjo
Copy link

samtjo commented Apr 25, 2022

Hi @merceyz - great library! It's been really handy on the project I work on.

We have come across this bug, take a look at this simple example component:

import React from "react";

interface ExampleProps {
  arrayProp: Array<string | undefined>;
}

const Example = ({ arrayProp }: ExampleProps) => {
  return arrayProp && <div>Example</div>;
};

export default Example;

The key part for this, is the arrayProp type is a union type that can be undefined. It causes the following error when calling the generate function from this package:

image

I think either the t.isUnionNode check needs to be able to handle one of the types in a union being undefined or we need a catch all if (t.isUndefinedNode(node)) check to return the correct type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant