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

Destructured Props in Functional Component #45

Open
skipjack opened this issue Mar 8, 2021 · 2 comments
Open

Destructured Props in Functional Component #45

skipjack opened this issue Mar 8, 2021 · 2 comments

Comments

@skipjack
Copy link

skipjack commented Mar 8, 2021

Thanks for your work on this. I just have a question for which I didn't see an answer in the README or open/closed issues, apologies if I missed it. Would the following inline type definitions in the following example be picked up and converted to prop types?

const MyComponent = ({
  title: string = 'Untitled',
  count: number = 0
}) => {
  return null
}

If not, would you be open to supporting it?

@milesj
Copy link
Owner

milesj commented Mar 8, 2021

@skipjack That syntax seems a bit invalid, do you mean something liek this?

const MyComponent = (props: {
  title: string,
  count: number,
  ...
}) => {
  return null
}

@skipjack
Copy link
Author

skipjack commented Mar 9, 2021

Good point! 🤦 Forgot that the aliasing operator within destructuring conflicts with type assignment (both :). Yeah so either what you had...

const MyComponent = (props: {
  title: string,
  count: number
}) => {
  return null
}

Where you'd have to reference props.title or props.count. Or the following which I verified here...

const MyComponent = ({
  title = 'Untitled',
  count = 0
}: {
  title: string,
  count: number
}) => {
  return null
}

Not sure if I love either, without aliasing in the way my first example (where I fixed the capitalization and added defaults) would be the most concise and clean imo but it is what it is. Anyway curious whether the other alternatives would be viable with this plugin?

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

2 participants