Skip to content

Commit 4b94d34

Browse files
committed
Correctly check for declarations property
1 parent a12e121 commit 4b94d34

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

repo-scripts/prune-dts/prune-dts.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function maybeHideConstructor(
163163
return ts.createConstructor(
164164
node.decorators,
165165
[modifier],
166-
/*parameters=*/ [],
166+
/*parameters=*/[],
167167
/* body= */ undefined
168168
);
169169
} else {
@@ -340,8 +340,8 @@ function extractJSDocComment(
340340
}
341341
});
342342

343-
if (comments.length > 0) {
344-
const jsDocTags = ts.getJSDocTags(symbol.declarations![overloadCount]);
343+
if (comments.length > 0 && symbol.declarations) {
344+
const jsDocTags = ts.getJSDocTags(symbol.declarations[overloadCount]);
345345
const maybeNewline = jsDocTags?.length > 0 ? '\n' : '';
346346
const joinedComments = comments
347347
.map(comment => {
@@ -412,19 +412,21 @@ function extractExportedSymbol(
412412
// See if there is an exported symbol that extends this private symbol.
413413
// In this case, we can safely use the public symbol instead.
414414
for (const symbol of allExportedSymbols) {
415-
for (const declaration of symbol.declarations!) {
416-
if (
417-
ts.isClassDeclaration(declaration) ||
418-
ts.isInterfaceDeclaration(declaration)
419-
) {
420-
for (const heritageClause of declaration.heritageClauses || []) {
421-
for (const type of heritageClause.types || []) {
422-
if (ts.isIdentifier(type.expression)) {
423-
const subclassName = type.expression.escapedText;
424-
if (subclassName === localSymbolName) {
425-
// TODO: We may need to change this to return a Union type if
426-
// more than one public type corresponds to the private type.
427-
return symbol;
415+
if (symbol.declarations) {
416+
for (const declaration of symbol.declarations) {
417+
if (
418+
ts.isClassDeclaration(declaration) ||
419+
ts.isInterfaceDeclaration(declaration)
420+
) {
421+
for (const heritageClause of declaration.heritageClauses || []) {
422+
for (const type of heritageClause.types || []) {
423+
if (ts.isIdentifier(type.expression)) {
424+
const subclassName = type.expression.escapedText;
425+
if (subclassName === localSymbolName) {
426+
// TODO: We may need to change this to return a Union type if
427+
// more than one public type corresponds to the private type.
428+
return symbol;
429+
}
428430
}
429431
}
430432
}
@@ -438,8 +440,8 @@ function extractExportedSymbol(
438440
// symbol. Note that this is not always safe as we might replace the local
439441
// symbol with a less restrictive type.
440442
const localSymbol = typeChecker.getSymbolAtLocation(typeName);
441-
if (localSymbol) {
442-
for (const declaration of localSymbol!.declarations!) {
443+
if (localSymbol?.declarations) {
444+
for (const declaration of localSymbol.declarations) {
443445
if (
444446
ts.isClassDeclaration(declaration) ||
445447
ts.isInterfaceDeclaration(declaration)
@@ -517,10 +519,10 @@ function dropPrivateApiTransformer(
517519
);
518520
return publicName
519521
? factory.updateTypeReferenceNode(
520-
node,
521-
factory.createIdentifier(publicName.name),
522-
node.typeArguments
523-
)
522+
node,
523+
factory.createIdentifier(publicName.name),
524+
node.typeArguments
525+
)
524526
: node;
525527
}
526528

0 commit comments

Comments
 (0)