Skip to content

Commit 0a700ea

Browse files
authored
Merge pull request #1523 from drwpow/chore/enforce-type
Chore: Enforce type imports
2 parents c87275a + 9fbcabf commit 0a700ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+75
-64
lines changed

.eslintrc.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ module.exports = {
1818
],
1919
rules: {
2020
"@typescript-eslint/consistent-indexed-object-style": "off", // sometimes naming keys is more user-friendly
21+
"@typescript-eslint/consistent-type-imports": [
22+
"error",
23+
{ prefer: "type-imports", fixStyle: "inline-type-imports" },
24+
],
2125
"@typescript-eslint/no-dynamic-delete": "off", // delete is OK
2226
"@typescript-eslint/no-non-null-assertion": "off", // this is better than "as"
2327
"@typescript-eslint/no-shadow": "error",

docs/6.x/advanced.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ And the magic that produces this would live in a `test/utils.ts` file that can b
8888
::: code-group [test/utils.ts]
8989

9090
```ts
91-
import { paths } from "./api/v1/my-schema"; // generated by openapi-typescript
91+
import type { paths } from "./api/v1"; // generated by openapi-typescript
9292

9393
// Settings
9494
// ⚠️ Important: change this! This prefixes all URLs

docs/6.x/cli.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export interface paths {
7171
Which means your type lookups also have to match the exact URL:
7272

7373
```ts
74-
import { paths } from "./my-schema";
74+
import type { paths } from "./api/v1";
7575

7676
const url = `/user/${id}`;
7777
type UserResponses = paths["/user/{user_id}"]["responses"];
@@ -80,7 +80,7 @@ type UserResponses = paths["/user/{user_id}"]["responses"];
8080
But when `--path-params-as-types` is enabled, you can take advantage of dynamic lookups like so:
8181

8282
```ts
83-
import { paths } from "./my-schema";
83+
import type { paths } from "./api/v1";
8484

8585
const url = `/user/${id}`;
8686
type UserResponses = paths[url]["responses"]; // automatically matches `paths['/user/{user_id}']`

docs/6.x/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Be sure to [validate your schemas](https://redocly.com/docs/cli/commands/lint/)!
5959
Then, import schemas from the generated file like so:
6060

6161
```ts
62-
import { paths, components } from "./path/to/my/schema"; // <- generated by openapi-typescript
62+
import type { paths, components } from "./api/v1"; // generated by openapi-typescript
6363

6464
// Schema Obj
6565
type MyType = components["schemas"]["MyType"];

docs/cli.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export interface paths {
115115
Which means your type lookups also have to match the exact URL:
116116

117117
```ts
118-
import { paths } from "./my-schema";
118+
import type{ paths } from "./api/v1";
119119
120120
const url = `/user/${id}`;
121121
type UserResponses = paths["/user/{user_id}"]["responses"];
@@ -124,7 +124,7 @@ type UserResponses = paths["/user/{user_id}"]["responses"];
124124
But when `--path-params-as-types` is enabled, you can take advantage of dynamic lookups like so:
125125

126126
```ts
127-
import { paths } from "./my-schema";
127+
import type { paths } from "./api/v1";
128128

129129
const url = `/user/${id}`;
130130
type UserResponses = paths[url]["responses"]; // automatically matches `paths['/user/{user_id}']`

docs/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ And the magic that produces this would live in a `test/utils.ts` file that can b
136136
::: code-group [test/utils.ts]
137137

138138
```ts
139-
import { paths } from "./api/v1/my-schema"; // generated by openapi-typescript
139+
import type { paths } from "./api/v1"; // generated by openapi-typescript
140140

141141
// Settings
142142
// ⚠️ Important: change this! This prefixes all URLs

docs/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ npx openapi-typescript https://myapi.dev/api/v1/openapi.yaml -o ./path/to/my/sch
5959
Then in your TypeScript project, import types where needed:
6060

6161
```ts
62-
import { paths, components } from "./path/to/my/schema"; // <- generated by openapi-typescript
62+
import type { paths, components } from "./api/v1"; // generated by openapi-typescript
6363

6464
// Schema Obj
6565
type MyType = components["schemas"]["MyType"];

docs/openapi-fetch/examples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Here’s how it can be handled using [Nano Stores](https://github.com/nanostores
1616
// src/lib/api/index.ts
1717
import { atom, computed } from "nanostores";
1818
import createClient from "openapi-fetch";
19-
import { paths } from "./v1";
19+
import type { paths } from "./api/v1";
2020

2121
export const authToken = atom<string | undefined>();
2222
someAuthMethod().then((newToken) => authToken.set(newToken));
@@ -47,7 +47,7 @@ You can also use [proxies](https://developer.mozilla.org/en-US/docs/Web/JavaScri
4747
```ts
4848
// src/lib/api/index.ts
4949
import createClient from "openapi-fetch";
50-
import { paths } from "./v1";
50+
import type { paths } from "./api/v1";
5151

5252
let authToken: string | undefined = undefined;
5353
someAuthMethod().then((newToken) => (authToken = newToken));
@@ -80,7 +80,7 @@ You can also use a [getter](https://developer.mozilla.org/en-US/docs/Web/JavaScr
8080
```ts
8181
// src/lib/api/index.ts
8282
import createClient from "openapi-fetch";
83-
import { paths } from "./v1";
83+
import type { paths } from "./api/v1";
8484

8585
let authToken: string | undefined = undefined;
8686
someAuthMethod().then((newToken) => (authToken = newToken));

docs/openapi-fetch/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The syntax is inspired by popular libraries like react-query or Apollo client, b
1818

1919
```ts
2020
import createClient from "openapi-fetch";
21-
import { paths } from "./v1"; // generated from openapi-typescript
21+
import type { paths } from "./api/v1"; // generated by openapi-typescript
2222

2323
const { GET, PUT } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
2424

@@ -102,7 +102,7 @@ The best part about using openapi-fetch over oldschool codegen is no documentati
102102

103103
```ts
104104
import createClient from "openapi-fetch";
105-
import { paths } from "./v1";
105+
import type { paths } from "./api/v1";
106106

107107
const { GET, PUT } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
108108

packages/openapi-fetch/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The syntax is inspired by popular libraries like react-query or Apollo client, b
1414

1515
```ts
1616
import createClient from "openapi-fetch";
17-
import { paths } from "./v1"; // generated from openapi-typescript
17+
import type { paths } from "./api/v1"; // generated by openapi-typescript
1818

1919
const { GET, PUT } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
2020

@@ -88,7 +88,7 @@ The best part about using openapi-fetch over oldschool codegen is no documentati
8888

8989
```ts
9090
import createClient from "openapi-fetch";
91-
import { paths } from "./v1";
91+
import type { paths } from "./api/v1";
9292

9393
const { GET, PUT } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
9494

0 commit comments

Comments
 (0)