Skip to content

Commit d560280

Browse files
committed
Fix typing
1 parent da22f83 commit d560280

File tree

1 file changed

+8
-8
lines changed
  • packages/gitbook/src/lib/openapi

1 file changed

+8
-8
lines changed

packages/gitbook/src/lib/openapi/fetch.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ export function resolveOpenAPIBlock<T extends OpenAPIBlockType = 'operation'>(
6464
): Promise<OpenAPIBlockResult<T>> {
6565
if (weakmap.has(args.block)) {
6666
// We enforce the type here cause weakmap doesn't know the type of the value
67-
return weakmap.get<AnyOpenAPIOperationBlock, Promise<OpenAPIBlockResult<T>>>(args.block);
67+
return weakmap.get(args.block) as Promise<OpenAPIBlockResult<T>>;
6868
}
6969

7070
const result = baseResolveOpenAPIBlock(args);
71-
weakmap.set(args.block, result);
71+
weakmap.set(args.block, result as Promise<OpenAPIBlockResult>);
7272
return result;
7373
}
7474

@@ -80,14 +80,14 @@ async function baseResolveOpenAPIBlock<T extends OpenAPIBlockType = 'operation'>
8080
): Promise<OpenAPIBlockResult<T>> {
8181
const { context, block, type = 'operation' } = args;
8282
if (!block.data.path || !block.data.method) {
83-
return createResults(null);
83+
return createResults<T>(null);
8484
}
8585

8686
const ref = block.data.ref;
8787
const resolved = ref ? await resolveContentRef(ref, context) : null;
8888

8989
if (!resolved) {
90-
return createResults(null);
90+
return createResults<T>(null);
9191
}
9292

9393
try {
@@ -109,7 +109,7 @@ async function baseResolveOpenAPIBlock<T extends OpenAPIBlockType = 'operation'>
109109
});
110110
}
111111

112-
return createResults(data, resolved.href);
112+
return createResults<T>(data, resolved.href);
113113
} catch (error) {
114114
if (error instanceof OpenAPIParseError) {
115115
return { error };
@@ -185,13 +185,13 @@ async function fetchFilesystemUncached(
185185
/**
186186
* Create a result for OpenAPI based on the type.
187187
*/
188-
function createResults<T extends OpenAPIOperationData | OpenAPIModelsData>(
189-
data: T | null,
188+
function createResults<T extends OpenAPIBlockType>(
189+
data: OpenAPIOperationData | OpenAPIModelsData | null,
190190
specUrl?: string
191191
): OpenAPIBlockResult<T> {
192192
return {
193193
error: undefined,
194194
data,
195195
specUrl,
196-
};
196+
} as OpenAPIBlockResult<T>;
197197
}

0 commit comments

Comments
 (0)