Skip to content

Commit

Permalink
Fixed handling optional binding elements in dts files
Browse files Browse the repository at this point in the history
Fixes #229

Co-authored-by: jinzhubaofu <ludafa@outlook.com>
  • Loading branch information
timocov and ludafa committed Nov 21, 2022
1 parent 0aba39e commit 2e1b1af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/types-usage-evaluator.ts
Expand Up @@ -89,6 +89,11 @@ export class TypesUsageEvaluator {
continue;
}

// `{ propertyName: name }` - in this case we don't need to handle `propertyName` as it has no symbol
if (ts.isBindingElement(child.parent) && child.parent.propertyName === child) {
continue;
}

const childSymbols = splitTransientSymbol(this.getSymbol(child), this.typeChecker);

for (const childSymbol of childSymbols) {
Expand All @@ -110,7 +115,7 @@ export class TypesUsageEvaluator {
private getSymbol(node: ts.Node): ts.Symbol {
const nodeSymbol = this.typeChecker.getSymbolAtLocation(node);
if (nodeSymbol === undefined) {
throw new Error(`Cannot find symbol for node: ${node.getText()}`);
throw new Error(`Cannot find symbol for node "${node.getText()}" in "${node.parent.getText()}" from "${node.getSourceFile().fileName}"`);
}

return this.getActualSymbol(nodeSymbol);
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/test-cases/primitive-generation/input.ts
Expand Up @@ -4,3 +4,7 @@ export interface InterfaceName {
prop: number;
prop2: TypeName;
}

export function func({ prop: prop3 }: InterfaceName = { prop: 1, prop2: 1 }): TypeName {
throw new Error('it does not matter' + prop3);
}
1 change: 1 addition & 0 deletions tests/e2e/test-cases/primitive-generation/output.d.ts
Expand Up @@ -3,5 +3,6 @@ export interface InterfaceName {
prop: number;
prop2: TypeName;
}
export declare function func({ prop: prop3 }?: InterfaceName): TypeName;

export {};

0 comments on commit 2e1b1af

Please sign in to comment.