Skip to content

Commit d9c3d96

Browse files
committed
chore: fix weird type narrowing issue
1 parent 790a0a4 commit d9c3d96

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

lib/process-document.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
VariableDeclarationKind,
1616
Writers,
1717
Scope,
18+
Node,
1819
} from 'ts-morph';
1920
import { registerTypesFromSchema, schemaToType } from './process-schema.js';
2021
import {
@@ -641,15 +642,20 @@ export async function processOpenApiDocument(
641642
SyntaxKind.CallExpression,
642643
);
643644

644-
callExpr?.addArguments(
645-
hasBody || hasQuery
646-
? [
647-
pathname,
648-
hasBody ? bodyName : 'undefined',
649-
...(hasQuery ? [`{${queryParameterNames.join(', ')}}`] : []),
650-
]
651-
: [pathname],
652-
);
645+
// type narrowing
646+
if (Node.isCallExpression(callExpr)) {
647+
callExpr.addArguments(
648+
hasBody || hasQuery
649+
? [
650+
pathname,
651+
hasBody ? bodyName : 'undefined',
652+
...(hasQuery
653+
? [`{${queryParameterNames.join(', ')}}`]
654+
: []),
655+
]
656+
: [pathname],
657+
);
658+
}
653659
}
654660
}
655661
}
@@ -742,11 +748,15 @@ export async function processOpenApiDocument(
742748
const callExpr = superKeyword?.getParentIfKindOrThrow(
743749
SyntaxKind.CallExpression,
744750
);
745-
callExpr?.addArguments([
746-
baseUrl.getName(),
747-
fetcherParam.getName(),
748-
configParam.getName(),
749-
]);
751+
752+
// type narrowing
753+
if (Node.isCallExpression(callExpr)) {
754+
callExpr?.addArguments([
755+
baseUrl.getName(),
756+
fetcherParam.getName(),
757+
configParam.getName(),
758+
]);
759+
}
750760

751761
return { commandsFile, typesFile, clientFile };
752762
}

0 commit comments

Comments
 (0)