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

Optional parameters #10

Open
1cedsoda opened this issue Feb 24, 2024 · 2 comments
Open

Optional parameters #10

1cedsoda opened this issue Feb 24, 2024 · 2 comments

Comments

@1cedsoda
Copy link

1cedsoda commented Feb 24, 2024

I want to generate this code. notice the optional method paramter.

export class Client {
  constructor(axiosInstance?: AxiosInstance) {
  }
}

This is my tsx:

<Class named="Client">
  <ClassMethod name="constructor" params={[
    <Identifier typeAnnotation="AxiosInstance">
      axiosInstance
    </Identifier>
  ]}>
  </ClassMethod>
</Class>

This code was generated:

class Client {
  constructor(axiosInstance: AxiosInstance) {
  }
}

How do I generate optional method parameters?

It would be great if there were some kinds of docs or more examples on how to build common js/ts patterns.

@clayrisser
Copy link
Owner

clayrisser commented Feb 24, 2024

I'm sorry I don't have docs yet. The names follow the same names used by the babel ast so if you poke around you'll probably find it. You can also look at the typescript types to see the available options. One helpful resource is https://astexplorer.net.

Just make sure that @babel/parser is enabled with tsx and jsx support.

astexp
2024-02-24-142251_screenshot

@clayrisser
Copy link
Owner

At the current moment it seems like it might not be supported. I can work on adding support for optional parameters.

There are 2 ways you can get around it in the meantime.

  1. Use an | undefined type.
  2. Use the <Smart /> component which basically let's you feed you code literally to it.

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