Skip to content

Commit fe3287c

Browse files
authored
fix(types): make $Fetch types less complex (#1059)
1 parent 300df93 commit fe3287c

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/build.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export async function writeTypes(nitro: Nitro) {
9292
routeTypes[mw.route][method] = [];
9393
}
9494
routeTypes[mw.route][method].push(
95-
`Awaited<ReturnType<typeof import('${relativePath}').default>>`
95+
`Simplify<Serialize<Awaited<ReturnType<typeof import('${relativePath}').default>>>>`
9696
);
9797
}
9898

@@ -117,6 +117,7 @@ export async function writeTypes(nitro: Nitro) {
117117

118118
const routes = [
119119
"// Generated by nitro",
120+
"import type { Serialize, Simplify } from 'nitropack'",
120121
"declare module 'nitropack' {",
121122
" type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T",
122123
" interface InternalApi {",

src/types/fetch.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { RouterMethod } from "h3";
22
import type { FetchRequest, FetchOptions, FetchResponse } from "ofetch";
3-
import type { Serialize } from "./serialize";
43
import type { MatchedRoutes } from "./utils";
54

65
// An interface to extend in a local project
@@ -13,12 +12,11 @@ export type NitroFetchRequest =
1312
// eslint-disable-next-line @typescript-eslint/ban-types
1413
| (string & {});
1514

16-
// TODO: re-enable Simplify
1715
export type MiddlewareOf<
1816
Route extends string,
1917
Method extends RouterMethod | "default"
2018
> = Method extends keyof InternalApi[MatchedRoutes<Route>]
21-
? Exclude<Serialize<InternalApi[MatchedRoutes<Route>][Method]>, Error | void>
19+
? Exclude<InternalApi[MatchedRoutes<Route>][Method], Error | void>
2220
: never;
2321

2422
export type TypedInternalResponse<

src/types/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./fetch";
2+
export * from "./serialize";
23
export * from "./nitro";
34
export * from "./handler";
45
export * from "./utils";

0 commit comments

Comments
 (0)