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

Raise warning when type unions are used #3592

Open
2 tasks
Chriscbr opened this issue Jun 9, 2022 · 0 comments
Open
2 tasks

Raise warning when type unions are used #3592

Chriscbr opened this issue Jun 9, 2022 · 0 comments
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1

Comments

@Chriscbr
Copy link
Contributor

Chriscbr commented Jun 9, 2022

Describe the feature

Add a warning in jsii that warns users if they are using a type union in a public API. This might be obtrusive to those not expecting these new warnings, so there should be a simple mechanism to disable this entire type of warning from appearing. Alternatively, this warning could be opt-in.

There should also be a mechanism for suppressing individual cases of this warning, for cases where the type union is intentional. This could be achieved through some configuration in package.json, or more preferably, some way to annotate the code inline like adding "@jsii-ignore type-union" to the method's docstring.

Use Case

Type unions should usually be aoivded when writing APIs with jsii because jsii will translate this into an opaque "Object" for languages like Java C#, and Go. That said, it's not forbidden because they do still work, and are available for when alternatives are not possible. But new users writing code for jsii-based libraries may not know this, so they may unintentionally write this TypeScript code out of the box.

Proposed Solution

No response

Other Information

There is an RFC to provide a better user experience around type unions: aws/aws-cdk-rfcs#194. That would nullify the need for this feature -- but also, raising this warning might be a good short-term fix, especially if type aliases requires a breaking change / a new version of JSII.

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

N/A

Environment details (OS name and version, etc.)

N/A

@Chriscbr Chriscbr added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 9, 2022
@peterwoodworth peterwoodworth added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

No branches or pull requests

2 participants