-
Notifications
You must be signed in to change notification settings - Fork 13
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
De-sugaring Type Aliases with arrays #1460
Comments
Relevant part of the jsii assembly:
|
I'd even go further and say the type should be (which is what the jsii assembly says): ```typescript
public readonly paramOne: Array<string | IOne>;
``` |
Yup, makes sense to me! |
Labelling this as a Contributions are welcomed and we aim to respond to all PRs as soon as possible. |
Having reviewed the docs it my understanding that JSII/JSII-Docgen de-sugars type aliases are de-sugared, this is a perfectly understandable design decision.
However I've come across a bit of a quirky behaviour as described below, and as is viewable in the minimum reproducible example repo I created.
As you can see, I am declaring parameter
paramOne
to expect an array of objects, I am not explicitly stating the type of the array as would be the case if I declaredstring[] | IOne[]
, thus from a TypeScript perspective, it will allow users to pass a mixed array of strings and objects matching interfaceIOne
, as is shown to be working in my example invocation.Current Behaviour
However the docs come out as
Which implies only the second type in the union can be an array, if a user were to attempt to use this as described in the docs they would get invalid code.
I believe this is an unintended consequence of the de-sugaring you are performing, and may require remediation?
Expected behaviour
Docgen should produce doc declaration for type paramOne as follows
Background
I am using this in a way where I want objects of interface
IOne
or strings in the interface, not both. I had declared my code as such as I found there were more optimal type guards available to me when I did it this way vs havingstring[] | IOne[]
The text was updated successfully, but these errors were encountered: