Commit 7c60a8ae authored by Jimmy Lai's avatar Jimmy Lai

refactor: reduce redundant unknown casts in stream ops

parent bca423c5
import type { Writable, Readable } from 'node:stream'
import type { Readable } from 'node:stream'
import type { PostponedState } from 'react-dom/static'
// Lazy require to avoid webpack trying to resolve node:stream at parse time.
......@@ -79,7 +79,7 @@ export function renderToFizzPipeableStream(
...options,
onHeaders: wrappedOnHeaders,
onShellReady() {
pipe(passthrough as unknown as Writable)
pipe(passthrough)
originalOnShellReady?.()
shellReady.resolve({
stream: passthrough,
......@@ -136,7 +136,7 @@ export function resumeToFizzPipeableStream(
}
)
pipe(passthrough as unknown as Writable)
pipe(passthrough)
return {
stream: passthrough,
......@@ -192,6 +192,6 @@ export function renderToFlightPipeableStream(
options as Parameters<FlightRenderToPipeableStream>[2]
)
)
run(() => pipe(passthrough as unknown as Writable))
run(() => pipe(passthrough))
return passthrough
}
......@@ -138,7 +138,7 @@ export async function resumeAndAbort(
postponed,
opts
)
return prelude as unknown as Readable
return prelude as Readable
}
export function renderToFlightStream(
......@@ -198,11 +198,11 @@ export async function resumeToFizzStream(
export function getServerPrerender(
ComponentMod: ServerPrerenderComponentMod
): (...args: any[]) => any {
return ComponentMod.prerenderToNodeStream! as unknown as (
...args: any[]
) => any
return ComponentMod.prerenderToNodeStream!
}
// Keep the same exported signature as stream-ops.web.ts. In node mode the
// underlying API returns a Node prelude stream instead of a web stream.
export const getClientPrerender: typeof import('react-dom/static').prerender =
prerenderToNodeStream as unknown as typeof getClientPrerender
......
......@@ -92,10 +92,10 @@ export function getFlightStream<T>(
if (debugStream instanceof Readable) {
nodeDebugStream = debugStream
} else {
// Cast through unknown: global ReadableStream and stream/web.ReadableStream
// differ slightly in type declarations.
// Node's fromWeb() overload expects stream/web.ReadableStream.
// Convert from the global ReadableStream type to satisfy that overload.
nodeDebugStream = Readable.fromWeb(
debugStream as unknown as import('stream/web').ReadableStream<Uint8Array>
debugStream as import('stream/web').ReadableStream<Uint8Array>
)
}
}
......
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