Skip to content

Commit 96ac5d6

Browse files
authored
fix(jsii): better usage reporting of private types (#247)
Anonymous types that are deduced by TypeScript get reported as: Cannot use private type __object in exported declarations The usage location would not be reported however, because the field 'symbol.valueDeclaration' was empty. There are locations in 'symbol.declarations' though, so we use that as a fallback instead, which works.
1 parent 6ad6b9d commit 96ac5d6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/jsii/lib/assembler.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,21 @@ export class Assembler implements Emitter {
202202
private async _getFQN(type: ts.Type): Promise<string> {
203203
const tsName = this._typeChecker.getFullyQualifiedName(type.symbol);
204204
const groups = tsName.match(/^\"([^\"]+)\"\.(.*)$/);
205+
let node = type.symbol.valueDeclaration;
206+
if (!node && type.symbol.declarations.length > 0) { node = type.symbol.declarations[0]; }
205207
if (!groups) {
206-
this._diagnostic(type.symbol.valueDeclaration, ts.DiagnosticCategory.Error, `Cannot use private type ${tsName} in exported declarations`);
208+
this._diagnostic(node, ts.DiagnosticCategory.Error, `Cannot use private type ${tsName} in exported declarations`);
207209
return tsName;
208210
}
209211
const [, modulePath, typeName, ] = groups;
210212
const pkg = await _findPackageInfo(modulePath);
211213
if (!pkg) {
212-
this._diagnostic(type.symbol.valueDeclaration, ts.DiagnosticCategory.Error, `Could not find module for ${modulePath}`);
214+
this._diagnostic(node, ts.DiagnosticCategory.Error, `Could not find module for ${modulePath}`);
213215
return `unknown.${typeName}`;
214216
}
215217
const fqn = `${pkg.name}.${typeName}`;
216218
if (pkg.name !== this.projectInfo.name && !this._dereference({ fqn }, type.symbol.valueDeclaration)) {
217-
this._diagnostic(type.symbol.valueDeclaration,
219+
this._diagnostic(node,
218220
ts.DiagnosticCategory.Error,
219221
`Use of foreign type not present in the ${pkg.name}'s assembly: ${fqn}`);
220222
}

0 commit comments

Comments
 (0)