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