Optional parameters
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.
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.
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.
- Use an
| undefinedtype. - Use the
<Smart />component which basically let's you feed you code literally to it.