Skip to content

Commit

Permalink
Better typings for AsyncIterator/Generator, like #31117
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Nov 28, 2019
1 parent 70b902e commit ab19818
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 504 deletions.
6 changes: 3 additions & 3 deletions src/lib/es2018.asyncgenerator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

interface AsyncGenerator<T = unknown, TReturn = any, TNext = unknown> extends AsyncIterator<T, TReturn, TNext> {
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
return(value: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T, TReturn>>;
throw(e: any): Promise<IteratorResult<T, TReturn>>;
next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn extends PromiseLike<infer UReturn> ? UReturn : TReturn>>;
return(value: TReturn): Promise<IteratorResult<T, TReturn extends PromiseLike<infer UReturn> ? UReturn : TReturn>>;
throw(e: any): Promise<IteratorResult<T, TReturn extends PromiseLike<infer UReturn> ? UReturn : TReturn>>;
[Symbol.asyncIterator](): AsyncGenerator<T, TReturn, TNext>;
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib/es2018.asynciterable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ interface SymbolConstructor {

interface AsyncIterator<T, TReturn = any, TNext = undefined> {
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
return?(value?: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T, TReturn>>;
throw?(e?: any): Promise<IteratorResult<T, TReturn>>;
next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn extends PromiseLike<infer UReturn> ? UReturn : TReturn>>;
return?(value?: TReturn): Promise<IteratorResult<T, TReturn extends PromiseLike<infer UReturn> ? UReturn : TReturn>>;
throw?(e?: any): Promise<IteratorResult<T, TReturn extends PromiseLike<infer UReturn> ? UReturn : TReturn>>;
}

interface AsyncIterable<T> {
Expand All @@ -22,4 +22,4 @@ interface AsyncIterable<T> {

interface AsyncIterableIterator<T> extends AsyncIterator<T> {
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
}
}
9 changes: 9 additions & 0 deletions tests/baselines/reference/user/TypeScript-Vue-Starter.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Exit Code: 1
Standard output:
src/components/Hello.spec.ts(4,1): error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.
src/components/Hello.spec.ts(5,3): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.
src/components/Hello.spec.ts(14,5): error TS2304: Cannot find name 'expect'.



Standard error:
18 changes: 11 additions & 7 deletions tests/baselines/reference/user/TypeScript-WeChat-Starter.log
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
Exit Code: 1
Standard output:
../../../../../node_modules/@types/mocha/index.d.ts(2680,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'beforeEach' must be of type 'Lifecycle', but here has type 'HookFunction'.
../../../../../node_modules/@types/mocha/index.d.ts(2698,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'afterEach' must be of type 'Lifecycle', but here has type 'HookFunction'.
../../../../../node_modules/@types/mocha/index.d.ts(2714,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'describe' must be of type 'Describe', but here has type 'SuiteFunction'.
../../../../../node_modules/@types/mocha/index.d.ts(2735,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'xdescribe' must be of type 'Describe', but here has type 'PendingSuiteFunction'.
../../../../../node_modules/@types/mocha/index.d.ts(2749,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'it' must be of type 'It', but here has type 'TestFunction'.
../../../../../node_modules/@types/mocha/index.d.ts(2763,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'test' must be of type 'It', but here has type 'TestFunction'.
../../../../../node_modules/@types/mocha/index.d.ts(2770,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'xit' must be of type 'It', but here has type 'PendingTestFunction'.
src/App.test.tsx(5,1): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.
src/components/Hello.test.tsx(5,1): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.
src/components/Hello.test.tsx(7,3): error TS2304: Cannot find name 'expect'.
src/components/Hello.test.tsx(10,1): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.
src/components/Hello.test.tsx(12,3): error TS2304: Cannot find name 'expect'.
src/components/Hello.test.tsx(15,1): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.
src/components/Hello.test.tsx(17,3): error TS2304: Cannot find name 'expect'.
src/components/Hello.test.tsx(20,1): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.
src/components/Hello.test.tsx(21,3): error TS2304: Cannot find name 'expect'.
src/components/Hello.test.tsx(26,1): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.
src/components/Hello.test.tsx(27,3): error TS2304: Cannot find name 'expect'.



Expand Down
Loading

0 comments on commit ab19818

Please sign in to comment.