-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(jsii): better errors around use of hidden types
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
- Loading branch information
1 parent
2cc4628
commit 17a551e
Showing
3 changed files
with
150 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
packages/jsii/test/negatives/neg.expose-unexported-type-internal-in-namespace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
///!MATCH_ERROR: Cannot use private type MyNamespace.UnexportedType in exported declarations | ||
///!MATCH_ERROR: Cannot internal type MyNamespace.UnexportedType as a property type in exported declarations | ||
|
||
// Attempt to expose an unexported type defined in this file should fail | ||
// because that type will not be available in the module spec. | ||
|
||
namespace MyNamespace { | ||
export class UnexportedType { | ||
} | ||
export class UnexportedType {} | ||
} | ||
|
||
export class ExportedType { | ||
public p?: MyNamespace.UnexportedType; | ||
public p?: MyNamespace.UnexportedType; | ||
} |
8 changes: 3 additions & 5 deletions
8
packages/jsii/test/negatives/neg.expose-unexported-type-internal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
///!MATCH_ERROR: Cannot use private type UnexportedType in exported declarations | ||
///!MATCH_ERROR: Type "UnexportedType" cannot be used as the property type because it is private or @internal | ||
|
||
// Attempt to expose an unexported type defined in this file should fail | ||
// because that type will not be available in the module spec. | ||
|
||
class UnexportedType { | ||
|
||
} | ||
class UnexportedType {} | ||
|
||
export class ExportedType { | ||
public p?: UnexportedType; | ||
public p?: UnexportedType; | ||
} |