Skip to content

Commit 29ae90d

Browse files
committed
falsy check
1 parent c50fc6d commit 29ae90d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/cli/src/metadataGeneration/exceptions.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ export class GenerateMetadataError extends Error {
1111
}
1212

1313
export class GenerateMetaDataWarning {
14-
constructor(private message: string, private node: Node | TypeNode, private onlyCurrent = false) { }
14+
constructor(
15+
private message: string,
16+
private node: Node | TypeNode,
17+
private onlyCurrent = false,
18+
) {}
1519

1620
toString() {
1721
return `Warning: ${this.message}\n${prettyLocationOfNode(this.node)}\n${prettyTroubleCause(this.node, this.onlyCurrent)}`;
@@ -34,9 +38,9 @@ export function prettyLocationOfNode(node: Node | TypeNode) {
3438
export function prettyTroubleCause(node: Node | TypeNode, onlyCurrent = false) {
3539
let name: string;
3640
if (onlyCurrent || !node.parent) {
37-
name = node.pos !== -1 ? node.getText() : ((node as any).name?.text || '<unknown name>');
41+
name = node.pos !== -1 && node.parent ? node.getText() : (node as any).name?.text || '<unknown name>';
3842
} else {
39-
name = node.parent.pos !== -1 ? node.parent.getText() : ((node as any).parent.name?.text || '<unknown name>');
43+
name = node.parent.pos !== -1 ? node.parent.getText() : (node as any).parent.name?.text || '<unknown name>';
4044
}
4145
return `This was caused by '${name}'`;
4246
}

tests/fixtures/controllers/getController.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ export class GetTestController extends Controller {
112112
return {} as TsoaTest.TestModel73;
113113
}
114114

115+
@Get('NamespaceWithTypeCastedObject')
116+
public async getNamespaceWithTypeCastedObject() {
117+
const test = { value: 'test' };
118+
return {
119+
value: test as TsoaTest.TestModel73,
120+
};
121+
}
122+
115123
@Get('Multi')
116124
public async getMultipleModels(): Promise<TestModel[]> {
117125
return [new ModelService().getModel(), new ModelService().getModel(), new ModelService().getModel()];

0 commit comments

Comments
 (0)