-
Notifications
You must be signed in to change notification settings - Fork 246
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
chore(jsii): better errors around use of hidden types #1861
chore(jsii): better errors around use of hidden types #1861
Conversation
Added another commit to actually switch the way we test for errors in the "negatives" to actually look at the rendered error entirely (thanks to jest snapshots) in order to have a better picture of the error UX we are offering. Marked |
@@ -1,5 +1,3 @@ | |||
///!MATCH_ERROR: Interface contains behavior: name should be "ISomething" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing this error (or equivalent) in the snapshot. Am I missing it, or did this get dropped somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😨 OMG good catch. I guess I was never asserting there is > 0 problems found...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh and the issue turned out to be essentially that location-less problem markers are NOT rendered with the API style I was going for... Dun dun dun!
When a hidden (that is, `@internal` or not exported) type is used in a visible (`public` or `protected` on an exported type) API, the error produced would refer to the unusable type, but would not give any indication of where it was being used from. This makes several enhancements to this process: - Qualify the kind of use for the type (return, parameter, ...) - Attach the error to the resolving node (usage location) - Provide a related message with the unusable type's declaration - Specifically message around "this" (used or inferred as a return type) This is going to particularly enhance the experience of folks extending internal base types, where those internal base types declare members that return hidden types (or "this"). Fixes #1860
Makes it easier to review the actual, complete, user experience (including error locality).
baeebbe
to
d7d1d1b
Compare
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Using `--project-references`, nested types from dependencies could not be used as they would result in the following `jsii` error: ``` Type "<type name>" cannot be used as the return type because it is private or @internal ``` THis is because in `--project-references` mode, the ambient declaration for the nested type is the declaration that gets resolved to, and those cannot have the `export` keyword: instead, the surrounding module declaration is annotated with `export ambient`. This adds the necessary code path to actually identify this scenario and to appropriately detect the type is actually visible and exported. The check that was failing had been added in #1861 as a way to provide a more helpful error message when private or `@internal` types are mistakenly used on exported APIs; which explains why this situation did not previously occur.
Using `--project-references`, nested types from dependencies could not be used as they would result in the following `jsii` error: ``` Type "<type name>" cannot be used as the return type because it is private or @internal ``` This is because in `--project-references` mode, the ambient declaration for the nested type is the declaration that gets resolved to, and those cannot have the `export` keyword: instead, the surrounding module declaration is annotated with `export ambient`. This adds the necessary code path to actually identify this scenario and to appropriately detect the type is actually visible and exported. The check that was failing had been added in #1861 as a way to provide a more helpful error message when private or `@internal` types are mistakenly used on exported APIs; which explains why this situation did not previously occur. > Hidden gem: we were previously adding the `static` keyword when > generating nested classes in **C#**. This is a **Java**-ism and results > in code that won't compile, since **C#** does not allow `static` nested > classes to declare `protected` members (which we actually emit some > of).
When a hidden (that is,
@internal
or not exported) type is used in avisible (
public
orprotected
on an exported type) API, the errorproduced would refer to the unusable type, but would not give any
indication of where it was being used from.
This makes several enhancements to this process:
This is going to particularly enhance the experience of folks extending
internal base types, where those internal base types declare members
that return hidden types (or "this").
Fixes #1860
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.