Unverified Commit 8a027d78 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Improve typing of `decodeReply` (#95263)

The types were unnecessarily specific (it doesn't always return a `T[]`)
parent a88f25ca
...@@ -780,7 +780,7 @@ export async function handleAction({ ...@@ -780,7 +780,7 @@ export async function handleAction({
return handleUnrecognizedFetchAction(err) return handleUnrecognizedFetchAction(err)
} }
boundActionArguments = await decodeReply( boundActionArguments = await decodeReply<unknown[]>(
formData, formData,
serverModuleMap, serverModuleMap,
{ temporaryReferences } { temporaryReferences }
...@@ -861,7 +861,7 @@ export async function handleAction({ ...@@ -861,7 +861,7 @@ export async function handleAction({
const actionData = Buffer.concat(chunks).toString('utf-8') const actionData = Buffer.concat(chunks).toString('utf-8')
boundActionArguments = await decodeReply( boundActionArguments = await decodeReply<unknown[]>(
actionData, actionData,
serverModuleMap, serverModuleMap,
{ temporaryReferences } { temporaryReferences }
...@@ -954,7 +954,7 @@ export async function handleAction({ ...@@ -954,7 +954,7 @@ export async function handleAction({
pipeline(body, sizeLimitTransform, busboy, { pipeline(body, sizeLimitTransform, busboy, {
signal: abortController.signal, signal: abortController.signal,
}), }),
decodeReplyFromBusboy(busboy, serverModuleMap, { decodeReplyFromBusboy<unknown[]>(busboy, serverModuleMap, {
temporaryReferences, temporaryReferences,
}), }),
]) ])
...@@ -1070,7 +1070,7 @@ export async function handleAction({ ...@@ -1070,7 +1070,7 @@ export async function handleAction({
const actionData = Buffer.concat(chunks).toString('utf-8') const actionData = Buffer.concat(chunks).toString('utf-8')
boundActionArguments = await decodeReply( boundActionArguments = await decodeReply<unknown[]>(
actionData, actionData,
serverModuleMap, serverModuleMap,
{ temporaryReferences } { temporaryReferences }
......
...@@ -117,9 +117,13 @@ export async function probeUseCache(msg: ProbeMessage): Promise<boolean> { ...@@ -117,9 +117,13 @@ export async function probeUseCache(msg: ProbeMessage): Promise<boolean> {
const temporaryReferences = createTemporaryReferenceSet() const temporaryReferences = createTemporaryReferenceSet()
let decoded: CacheKeyParts let decoded: CacheKeyParts
if (msg.encodedArguments.kind === 'string') { if (msg.encodedArguments.kind === 'string') {
decoded = (await decodeReply(msg.encodedArguments.data, serverModuleMap, { decoded = await decodeReply<CacheKeyParts>(
temporaryReferences, msg.encodedArguments.data,
})) as CacheKeyParts serverModuleMap,
{
temporaryReferences,
}
)
} else { } else {
const entries = msg.encodedArguments.entries.map<[string, string | File]>( const entries = msg.encodedArguments.entries.map<[string, string | File]>(
([key, value]) => { ([key, value]) => {
...@@ -130,7 +134,7 @@ export async function probeUseCache(msg: ProbeMessage): Promise<boolean> { ...@@ -130,7 +134,7 @@ export async function probeUseCache(msg: ProbeMessage): Promise<boolean> {
return [key, new File([bytes], '', { type: value.type })] return [key, new File([bytes], '', { type: value.type })]
} }
) )
decoded = (await decodeReplyFromAsyncIterable( decoded = await decodeReplyFromAsyncIterable<CacheKeyParts>(
{ {
async *[Symbol.asyncIterator]() { async *[Symbol.asyncIterator]() {
for (const pair of entries) { for (const pair of entries) {
...@@ -140,7 +144,7 @@ export async function probeUseCache(msg: ProbeMessage): Promise<boolean> { ...@@ -140,7 +144,7 @@ export async function probeUseCache(msg: ProbeMessage): Promise<boolean> {
}, },
serverModuleMap, serverModuleMap,
{ temporaryReferences } { temporaryReferences }
)) as CacheKeyParts )
} }
const args = decoded[2] const args = decoded[2]
......
...@@ -279,17 +279,17 @@ declare module 'react-server-dom-webpack/server.node' { ...@@ -279,17 +279,17 @@ declare module 'react-server-dom-webpack/server.node' {
...args: unknown[] ...args: unknown[]
): TemporaryReferenceSet ): TemporaryReferenceSet
export function decodeReplyFromBusboy( export function decodeReplyFromBusboy<T>(
busboyStream: Busboy, busboyStream: Busboy,
webpackMap: ServerManifest, webpackMap: ServerManifest,
options?: { temporaryReferences?: TemporaryReferenceSet } options?: { temporaryReferences?: TemporaryReferenceSet }
): Promise<unknown[]> ): Promise<T>
export function decodeReply<T>( export function decodeReply<T>(
body: string | FormData, body: string | FormData,
webpackMap: ServerManifest, webpackMap: ServerManifest,
options?: { temporaryReferences?: TemporaryReferenceSet } options?: { temporaryReferences?: TemporaryReferenceSet }
): Promise<T[]> ): Promise<T>
export function decodeAction( export function decodeAction(
body: FormData, body: FormData,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment