Skip to content

Commit dfa92ba

Browse files
authored
Fixed ServerErrorStatus, ClientErrorStatus not being imported as type (#98)
This causes errors when tsconfig.json has "importsNotUsedAsValues" set to "error"
1 parent 7879199 commit dfa92ba

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

plugins/typescript/src/core/createNamedImport.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import { factory as f } from "typescript";
55
*
66
* @param fnName functions to imports
77
* @param filename path of the module
8+
* @param isTypeOnly whether fnName are used as types only
89
* @returns ts.Node of the import declaration
910
*/
1011
export const createNamedImport = (
1112
fnName: string | string[],
12-
filename: string
13+
filename: string,
14+
isTypeOnly = false
1315
) => {
1416
const fnNames = Array.isArray(fnName) ? fnName : [fnName];
1517
return f.createImportDeclaration(
1618
undefined,
1719
f.createImportClause(
18-
false,
20+
isTypeOnly,
1921
undefined,
2022
f.createNamedImports(
2123
fnNames.map((name) =>

plugins/typescript/src/core/getUsedImports.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ describe("getUsedImports", () => {
223223
.nodes.map(print)
224224
.join("\n")
225225
).toMatchInlineSnapshot(
226-
`"import { ClientErrorStatus } from \\"././utils\\";"`
226+
`"import type { ClientErrorStatus } from \\"././utils\\";"`
227227
);
228228
});
229229

@@ -253,7 +253,7 @@ describe("getUsedImports", () => {
253253
.nodes.map(print)
254254
.join("\n")
255255
).toMatchInlineSnapshot(
256-
`"import { ServerErrorStatus } from \\"././utils\\";"`
256+
`"import type { ServerErrorStatus } from \\"././utils\\";"`
257257
);
258258
});
259259

@@ -294,7 +294,7 @@ describe("getUsedImports", () => {
294294
.nodes.map(print)
295295
.join("\n")
296296
).toMatchInlineSnapshot(
297-
`"import { ServerErrorStatus, ClientErrorStatus } from \\"././utils\\";"`
297+
`"import type { ServerErrorStatus, ClientErrorStatus } from \\"././utils\\";"`
298298
);
299299
});
300300
});

plugins/typescript/src/core/getUsedImports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const getUsedImports = (
8989
if (i.type === "namespace") {
9090
return createNamespaceImport(i.namespace, `./${i.from}`);
9191
} else {
92-
return createNamedImport(Array.from(i.imports.values()), `./${i.from}`);
92+
return createNamedImport(Array.from(i.imports.values()), `./${i.from}`, true);
9393
}
9494
}),
9595
};

plugins/typescript/src/generators/generateFetchers.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("generateFetchers", () => {
8181
import { petstoreFetch } from \\"./petstoreFetcher\\";
8282
import type * as Schemas from \\"./petstoreSchemas\\";
8383
import type * as Responses from \\"./petstoreResponses\\";
84-
import { ServerErrorStatus } from \\"./petstoreUtils\\";
84+
import type { ServerErrorStatus } from \\"./petstoreUtils\\";
8585
8686
export type ListPetsError = Fetcher.ErrorWrapper<{
8787
status: 404;
@@ -125,7 +125,7 @@ describe("generateFetchers", () => {
125125
import { fetch } from \\"./fetcher\\";
126126
import type * as Schemas from \\"./petstoreSchemas\\";
127127
import type * as Responses from \\"./petstoreResponses\\";
128-
import { ServerErrorStatus } from \\"./utils\\";
128+
import type { ServerErrorStatus } from \\"./utils\\";
129129
130130
export type ListPetsError = Fetcher.ErrorWrapper<{
131131
status: 404;
@@ -176,7 +176,7 @@ describe("generateFetchers", () => {
176176
import { petstoreFetch, PetstoreFetcherExtraProps } from \\"./petstoreFetcher\\";
177177
import type * as Schemas from \\"./petstoreSchemas\\";
178178
import type * as Responses from \\"./petstoreResponses\\";
179-
import { ServerErrorStatus } from \\"./petstoreUtils\\";
179+
import type { ServerErrorStatus } from \\"./petstoreUtils\\";
180180
181181
export type ListPetsError = Fetcher.ErrorWrapper<{
182182
status: 404;
@@ -228,7 +228,7 @@ describe("generateFetchers", () => {
228228
import { petstoreFetch } from \\"./petstoreFetcher\\";
229229
import type * as Schemas from \\"./petstoreSchemas\\";
230230
import type * as Responses from \\"./petstoreResponses\\";
231-
import { ServerErrorStatus } from \\"./petstoreUtils\\";
231+
import type { ServerErrorStatus } from \\"./petstoreUtils\\";
232232
233233
export type ListPetsError = Fetcher.ErrorWrapper<{
234234
status: 404;

plugins/typescript/src/generators/generateReactQueryComponents.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ describe("generateReactQueryComponents", () => {
11431143
import type * as Fetcher from \\"./petstoreFetcher\\";
11441144
import { petstoreFetch } from \\"./petstoreFetcher\\";
11451145
import type * as Schemas from \\"./petstoreSchemas\\";
1146-
import { ServerErrorStatus } from \\"./petstoreUtils\\";
1146+
import type { ServerErrorStatus } from \\"./petstoreUtils\\";
11471147
11481148
export type ListPetsError = Fetcher.ErrorWrapper<{
11491149
status: ServerErrorStatus;

0 commit comments

Comments
 (0)