From d7a5b9d9af4de56c69a446291a5f54a90a81494b Mon Sep 17 00:00:00 2001 From: Chaz Gatian Date: Thu, 5 Jun 2025 17:50:58 -0400 Subject: [PATCH] fix: declaration array can be undefined --- src/parser.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index 1bba7c0..4d5ed4d 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -266,10 +266,9 @@ export class Parser { if (exp.flags & ts.SymbolFlags.Alias) { targetSymbol = this.checker.getAliasedSymbol(exp); } - const declaration = - targetSymbol.valueDeclaration || targetSymbol.declarations![0]; + const declaration = targetSymbol.valueDeclaration; - if (ts.isClassDeclaration(declaration)) { + if (!declaration || ts.isClassDeclaration(declaration)) { return false; } @@ -1203,7 +1202,11 @@ export class Parser { properties: ts.NodeArray ): StringIndexedObject { return properties.reduce((acc, property) => { - const propertyName = getPropertyName(ts.isBindingElement(property) ? (property.propertyName || property.name) : property.name); + const propertyName = getPropertyName( + ts.isBindingElement(property) + ? property.propertyName || property.name + : property.name + ); if (ts.isSpreadAssignment(property) || !propertyName) { return acc; } @@ -1211,10 +1214,10 @@ export class Parser { const literalValue = this.getLiteralValueFromPropertyAssignment(property); if ( - (typeof literalValue === 'string' || - typeof literalValue === 'number' || - typeof literalValue === 'boolean' || - literalValue === null) + typeof literalValue === 'string' || + typeof literalValue === 'number' || + typeof literalValue === 'boolean' || + literalValue === null ) { acc[propertyName] = literalValue; }