Skip to content

Commit

Permalink
feat: type {} use Record<string, never> replace
Browse files Browse the repository at this point in the history
  • Loading branch information
liangskyli committed Apr 20, 2023
1 parent 5abcacd commit ba819fd
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/openapi-gen-ts/src/gen/gen-interface-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const genInterfaceFile = async (opts: IOpts) => {

const requestAPI: string[] = [];
requestAPI.push(`${fileTip}
/* eslint-disable @typescript-eslint/ban-types */
${
requestParamsType !== ''
? `import type {${requestParamsType} } from '${
Expand Down Expand Up @@ -149,11 +148,13 @@ const genInterfaceFile = async (opts: IOpts) => {
}

interfaceAPIType.push(`'${url}': {`);
requestAPI.push(`'${url}': <T extends Record<any, any> = {}>(
requestAPI.push(`'${url}': <T extends Record<any, any> = Record<string, never>>(
config: IConfig<
${IConfigT.length > 0 ? IConfigT.join('') : 'T,'}
{
`);
requestAPI.push(
!haveQuery && !haveBody ? 'Record<string, never>' : '{',
);
if (haveQuery) {
const omitKeys = requestQueryOmit
.map((omitItem) => `'${omitItem}'`)
Expand Down Expand Up @@ -195,8 +196,10 @@ const genInterfaceFile = async (opts: IOpts) => {
`Response: paths['${url}']['${method}']['responses']['200']['content']['${responseMediaType}'];`,
);
interfaceAPIType.push('};');
requestAPI.push(`}
>,
if (haveQuery || haveBody) {
requestAPI.push('}');
}
requestAPI.push(`>,
): Promise<IApi['${url}']['Response']> => {
const { ${haveQuery ? 'params,' : ''} ${
haveBody ? 'data,' : ''
Expand Down

0 comments on commit ba819fd

Please sign in to comment.