Skip to content

Commit

Permalink
Improve typing for Generators and Async Generators
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Apr 6, 2019
1 parent 645853a commit 03afdb4
Show file tree
Hide file tree
Showing 270 changed files with 3,064 additions and 1,645 deletions.
790 changes: 564 additions & 226 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace ts {
["es2017.string", "lib.es2017.string.d.ts"],
["es2017.intl", "lib.es2017.intl.d.ts"],
["es2017.typedarrays", "lib.es2017.typedarrays.d.ts"],
["es2018.asyncgenerator", "lib.es2018.asyncgenerator.d.ts"],
["es2018.asynciterable", "lib.es2018.asynciterable.d.ts"],
["es2018.intl", "lib.es2018.intl.d.ts"],
["es2018.promise", "lib.es2018.promise.d.ts"],
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3899,6 +3899,10 @@
"category": "Message",
"code": 6217
},
"Enable strict checking of generator types.": {
"category": "Message",
"code": 6218
},

"Projects to reference": {
"category": "Message",
Expand Down Expand Up @@ -4256,6 +4260,10 @@
"category": "Error",
"code": 7051
},
"Generator implicitly has type '{0}' because it does not yield or return any values. Consider supplying a return type.": {
"category": "Error",
"code": 7052
},

"You cannot rename this element.": {
"category": "Error",
Expand Down
16 changes: 12 additions & 4 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4226,13 +4226,21 @@ namespace ts {
regularType: ResolvedType; // Regular version of fresh type
}

/* @internal */
export interface IterationTypes {
yieldType?: Type;
returnType?: Type;
nextType?: Type;
}

// Just a place to cache element types of iterables and iterators
/* @internal */
export interface IterableOrIteratorType extends ObjectType, UnionType {
iteratedTypeOfIterable?: Type;
iteratedTypeOfIterator?: Type;
iteratedTypeOfAsyncIterable?: Type;
iteratedTypeOfAsyncIterator?: Type;
iterationTypesOfIterable?: IterationTypes;
iterationTypesOfIterator?: IterationTypes;
iterationTypesOfAsyncIterable?: IterationTypes;
iterationTypesOfAsyncIterator?: IterationTypes;
iterationTypesOfIteratorResult?: IterationTypes;
}

/* @internal */
Expand Down
9 changes: 8 additions & 1 deletion src/lib/es2015.generator.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
interface Generator extends Iterator<any> { }
/// <reference lib="es2015.iterable" />

interface Generator<TYield = unknown, TReturn = void, TNext = unknown> {
next(value?: TNext): IteratorResult<TYield, TReturn>;
return(value: TReturn): IteratorResult<TYield, TReturn>;
throw(e: any): IteratorResult<TYield, TReturn>;
[Symbol.iterator](): Generator<TYield, TReturn, TNext>;
}

interface GeneratorFunction {
/**
Expand Down
Loading

0 comments on commit 03afdb4

Please sign in to comment.