-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing properties on *StreamLike types in TypeScript #23
Comments
The Thanks for reporting. I'll see if I can improve the types. 🙂 |
Hmm, this might be impossible. 😕
const toPolyfillReadable = createReadableStreamWrapper(PolyfillReadableStream);
const readable1: PolyfillReadableStream<string> = toPolyfillReadable(new ReadableStream<string>());
const readable2: PolyfillReadableStream<Uint8Array> = toPolyfillReadable(new ReadableStream<Uint8Array>()); To correctly express this, we'd need some sort of "higher kinded types", which doesn't exist yet in TypeScript: // pseudo code, not real TypeScript
export interface ReadableStreamLikeConstructor<RS extends ReadableStreamLike<?>> {
// ~~~ not possible
new<R = any>(
underlyingSource?: UnderlyingSource<R>,
strategy?: QueuingStrategy<R>
): RS<R>;
// ~~~~~ not possible
}
export type ReadableStreamWrapper<RS extends ReadableStreamLike<?>>
= <R>(readable: ReadableStreamLike<R>) => RS<R>;
export function createReadableStreamWrapper<RS extends ReadableStreamLike<?>>(
ctor: ReadableStreamLikeConstructor<RS>
): ReadableStreamWrapper<RS> { /* ... */ } For the time being, you'll need to manually cast the return value to the desired type yourself: const toPolyfillReadable = createReadableStreamWrapper(PolyfillReadableStream);
const readable1 = toPolyfillReadable(new ReadableStream<string>()) as PolyfillReadableStream<string>;
const readable2 = toPolyfillReadable(new ReadableStream<Uint8Array>()) as PolyfillReadableStream<Uint8Array>; I wish I had a better answer. 😞 I am trying to make |
Sorry to abuse the issue tracker this way, but do you have a Paypal or BuyMeACoffee or something where I can thank you for your work? It's just really great stuff. |
Thanks for the kind words! 😊 I'm fortunate enough to have a great day job, so I'd feel bad to accept donations. But if you want, you can sponsor other projects and developers, or donate to a charity. |
First of all, much love for your work here and on the polyfill!
When using this library with TypeScript, if I do something like:
it says:
Maybe the properties from https://github.com/microsoft/TypeScript/blob/fd6552a3c2fdfe92afd88ccf6616ec02946e7d9e/lib/lib.dom.d.ts#L11917-L11925 should be copied to
web-streams-adapter/src/stream-like.ts
Lines 20 to 24 in bff7004
The text was updated successfully, but these errors were encountered: