Skip to content

Commit

Permalink
fix(types): make $Fetch types less complex (#1059)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdiboomeri authored Mar 22, 2023
1 parent 300df93 commit fe3287c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function writeTypes(nitro: Nitro) {
routeTypes[mw.route][method] = [];
}
routeTypes[mw.route][method].push(
`Awaited<ReturnType<typeof import('${relativePath}').default>>`
`Simplify<Serialize<Awaited<ReturnType<typeof import('${relativePath}').default>>>>`
);
}

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

const routes = [
"// Generated by nitro",
"import type { Serialize, Simplify } from 'nitropack'",
"declare module 'nitropack' {",
" type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T",
" interface InternalApi {",
Expand Down
4 changes: 1 addition & 3 deletions src/types/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { RouterMethod } from "h3";
import type { FetchRequest, FetchOptions, FetchResponse } from "ofetch";
import type { Serialize } from "./serialize";
import type { MatchedRoutes } from "./utils";

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

// TODO: re-enable Simplify
export type MiddlewareOf<
Route extends string,
Method extends RouterMethod | "default"
> = Method extends keyof InternalApi[MatchedRoutes<Route>]
? Exclude<Serialize<InternalApi[MatchedRoutes<Route>][Method]>, Error | void>
? Exclude<InternalApi[MatchedRoutes<Route>][Method], Error | void>
: never;

export type TypedInternalResponse<
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./fetch";
export * from "./serialize";
export * from "./nitro";
export * from "./handler";
export * from "./utils";
Expand Down

0 comments on commit fe3287c

Please sign in to comment.