const request: RequestInfo = {
method,
cache,
redirect,
headers: {} as Headers,
body: null as string | null,
};
...
fetch(url, request);
使用以上方法,我得到了:
Type 'string | null' is not assignable to type 'ReadableStream<Uint8Array> | null'.
Type 'string' is not assignable to type 'ReadableStream<Uint8Array> | null'.
在TS的类型声明中,有:
interface RequestInit {
/**
* A BodyInit object or null to set request's body.
*/
body?: BodyInit | null;
}
type BodyInit = Blob | BufferSource | FormData | URLSearchParams | ReadableStream<Uint8Array> | string;
为什么它期望 ReadableStream<Uint8Array>
?