Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Feb 24, 2020
1 parent 0662010 commit 759506e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
11 changes: 6 additions & 5 deletions etc/web-streams-polyfill.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ export type ReadableStreamDefaultController<R> = ReadableStreamDefaultController
export type ReadableStreamDefaultReader<R> = ReadableStreamDefaultReader_2<R>;

// @public (undocumented)
export interface ReadResult<T = any> {
// (undocumented)
done: boolean;
// (undocumented)
export type ReadResult<T> = {
done: false;
value: T;
}
} | {
done: true;
value?: T;
};

// @public (undocumented)
export interface Transformer<I = any, O = any> {
Expand Down
7 changes: 4 additions & 3 deletions src/lib/readable-stream/async-iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
ReadableStreamCreateReadResult,
ReadableStreamReaderGenericCancel,
ReadableStreamReaderGenericRelease,
readerLockException
readerLockException,
ReadResult
} from './generic-reader';
import assert from '../../stub/assert';
import { promiseRejectedWith, promiseResolvedWith, transformPromiseWith, typeIsObject } from '../helpers';
Expand All @@ -34,7 +35,7 @@ declare class ReadableStreamAsyncIteratorImpl<R> implements ReadableStreamAsyncI
}

const ReadableStreamAsyncIteratorPrototype: ReadableStreamAsyncIteratorImpl<any> = {
next(): Promise<IteratorResult<any>> {
next(this: ReadableStreamAsyncIteratorImpl<any>): Promise<ReadResult<any>> {
if (IsReadableStreamAsyncIterator(this) === false) {
return promiseRejectedWith(streamAsyncIteratorBrandCheckException('next'));
}
Expand All @@ -54,7 +55,7 @@ const ReadableStreamAsyncIteratorPrototype: ReadableStreamAsyncIteratorImpl<any>
});
},

return(value: any): Promise<IteratorResult<any>> {
return(this: ReadableStreamAsyncIteratorImpl<any>, value: any): Promise<ReadResult<any>> {
if (IsReadableStreamAsyncIterator(this) === false) {
return promiseRejectedWith(streamAsyncIteratorBrandCheckException('next'));
}
Expand Down
8 changes: 5 additions & 3 deletions src/lib/readable-stream/generic-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import assert from '../../stub/assert';
import { ReadableStream, ReadableStreamCancel, ReadableStreamReader } from '../readable-stream';
import { newPromise, setPromiseIsHandledToTrue } from '../helpers';

// TODO Fix ReadableStreamReadResult<R> in TypeScript DOM types
export interface ReadResult<T = any> {
done: boolean;
export type ReadResult<T> = {
done: false;
value: T;
} | {
done: true;
value?: T;
}

export function ReadableStreamCreateReadResult<T>(value: T | undefined,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/readable-stream/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ export function ReadableStreamPipeTo<T>(source: ReadableStream<T>,
}

return PerformPromiseThen(writer._readyPromise, () => {
return PerformPromiseThen(ReadableStreamDefaultReaderRead(reader), ({ value, done }) => {
if (done === true) {
return PerformPromiseThen(ReadableStreamDefaultReaderRead(reader), result => {
if (result.done === true) {
return true;
}

currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, value), undefined, noop);
currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, result.value), undefined, noop);
return false;
});
});
Expand Down

0 comments on commit 759506e

Please sign in to comment.