Skip to content

Commit 6f530cc

Browse files
authored
Add TReturn/TNext to Iterable et al (#58243)
1 parent f8a7913 commit 6f530cc

File tree

163 files changed

+3476
-1056
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+3476
-1056
lines changed

src/compiler/checker.ts

+63-72
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

+10
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,16 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
914914
description: Diagnostics.Check_for_class_properties_that_are_declared_but_not_set_in_the_constructor,
915915
defaultValueDescription: Diagnostics.false_unless_strict_is_set,
916916
},
917+
{
918+
name: "strictBuiltinIteratorReturn",
919+
type: "boolean",
920+
affectsSemanticDiagnostics: true,
921+
affectsBuildInfo: true,
922+
strictFlag: true,
923+
category: Diagnostics.Type_Checking,
924+
description: Diagnostics.Built_in_iterators_are_instantiated_with_a_TReturn_type_of_undefined_instead_of_any,
925+
defaultValueDescription: Diagnostics.false_unless_strict_is_set,
926+
},
917927
{
918928
name: "noImplicitThis",
919929
type: "boolean",

src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -6372,6 +6372,10 @@
63726372
"code": 6719
63736373
},
63746374

6375+
"Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'.": {
6376+
"category": "Message",
6377+
"code": 6720
6378+
},
63756379
"Default catch clause variables as 'unknown' instead of 'any'.": {
63766380
"category": "Message",
63776381
"code": 6803

src/compiler/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5238,7 +5238,7 @@ export interface TypeChecker {
52385238
/** @internal */ createPromiseType(type: Type): Type;
52395239
/** @internal */ getPromiseType(): Type;
52405240
/** @internal */ getPromiseLikeType(): Type;
5241-
/** @internal */ getAsyncIterableType(): Type | undefined;
5241+
/** @internal */ getAnyAsyncIterableType(): Type | undefined;
52425242

52435243
/**
52445244
* Returns true if the "source" type is assignable to the "target" type.
@@ -7408,6 +7408,7 @@ export interface CompilerOptions {
74087408
strictBindCallApply?: boolean; // Always combine with strict property
74097409
strictNullChecks?: boolean; // Always combine with strict property
74107410
strictPropertyInitialization?: boolean; // Always combine with strict property
7411+
strictBuiltinIteratorReturn?: boolean; // Always combine with strict property
74117412
stripInternal?: boolean;
74127413
/** @deprecated */
74137414
suppressExcessPropertyErrors?: boolean;

src/compiler/utilities.ts

+7
Original file line numberDiff line numberDiff line change
@@ -9006,6 +9006,12 @@ export const computedOptions = createComputedCompilerOptions({
90069006
return getStrictOptionValue(compilerOptions, "strictPropertyInitialization");
90079007
},
90089008
},
9009+
strictBuiltinIteratorReturn: {
9010+
dependencies: ["strict"],
9011+
computeValue: compilerOptions => {
9012+
return getStrictOptionValue(compilerOptions, "strictBuiltinIteratorReturn");
9013+
},
9014+
},
90099015
alwaysStrict: {
90109016
dependencies: ["strict"],
90119017
computeValue: compilerOptions => {
@@ -9093,6 +9099,7 @@ export type StrictOptionName =
90939099
| "strictFunctionTypes"
90949100
| "strictBindCallApply"
90959101
| "strictPropertyInitialization"
9102+
| "strictBuiltinIteratorReturn"
90969103
| "alwaysStrict"
90979104
| "useUnknownInCatchVariables";
90989105

src/harness/collectionsImpl.ts

+3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export class SortedMap<K, V> {
132132
this._copyOnWrite = false;
133133
}
134134
}
135+
return undefined;
135136
}
136137

137138
public *values() {
@@ -154,6 +155,7 @@ export class SortedMap<K, V> {
154155
this._copyOnWrite = false;
155156
}
156157
}
158+
return undefined;
157159
}
158160

159161
public *entries() {
@@ -179,6 +181,7 @@ export class SortedMap<K, V> {
179181
this._copyOnWrite = false;
180182
}
181183
}
184+
return undefined;
182185
}
183186

184187
public [Symbol.iterator]() {

src/lib/dom.iterable.d.ts

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
/// <reference lib="dom" />
22

33
interface DOMTokenList {
4-
[Symbol.iterator](): IterableIterator<string>;
4+
[Symbol.iterator](): IterableIterator<string, BuiltinIteratorReturn>;
55
}
66

77
interface Headers {
8-
[Symbol.iterator](): IterableIterator<[string, string]>;
8+
[Symbol.iterator](): IterableIterator<[string, string], BuiltinIteratorReturn>;
99
/**
1010
* Returns an iterator allowing to go through all key/value pairs contained in this object.
1111
*/
12-
entries(): IterableIterator<[string, string]>;
12+
entries(): IterableIterator<[string, string], BuiltinIteratorReturn>;
1313
/**
1414
* Returns an iterator allowing to go through all keys f the key/value pairs contained in this object.
1515
*/
16-
keys(): IterableIterator<string>;
16+
keys(): IterableIterator<string, BuiltinIteratorReturn>;
1717
/**
1818
* Returns an iterator allowing to go through all values of the key/value pairs contained in this object.
1919
*/
20-
values(): IterableIterator<string>;
20+
values(): IterableIterator<string, BuiltinIteratorReturn>;
2121
}
2222

2323
interface NodeList {
2424
/**
2525
* Returns an array of key, value pairs for every entry in the list
2626
*/
27-
entries(): IterableIterator<[number, Node]>;
27+
entries(): IterableIterator<[number, Node], BuiltinIteratorReturn>;
2828
/**
2929
* Performs the specified action for each node in an list.
3030
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the list.
@@ -34,21 +34,21 @@ interface NodeList {
3434
/**
3535
* Returns an list of keys in the list
3636
*/
37-
keys(): IterableIterator<number>;
37+
keys(): IterableIterator<number, BuiltinIteratorReturn>;
3838

3939
/**
4040
* Returns an list of values in the list
4141
*/
42-
values(): IterableIterator<Node>;
42+
values(): IterableIterator<Node, BuiltinIteratorReturn>;
4343

44-
[Symbol.iterator](): IterableIterator<Node>;
44+
[Symbol.iterator](): IterableIterator<Node, BuiltinIteratorReturn>;
4545
}
4646

4747
interface NodeListOf<TNode extends Node> {
4848
/**
4949
* Returns an array of key, value pairs for every entry in the list
5050
*/
51-
entries(): IterableIterator<[number, TNode]>;
51+
entries(): IterableIterator<[number, TNode], BuiltinIteratorReturn>;
5252

5353
/**
5454
* Performs the specified action for each node in an list.
@@ -59,55 +59,55 @@ interface NodeListOf<TNode extends Node> {
5959
/**
6060
* Returns an list of keys in the list
6161
*/
62-
keys(): IterableIterator<number>;
62+
keys(): IterableIterator<number, BuiltinIteratorReturn>;
6363
/**
6464
* Returns an list of values in the list
6565
*/
66-
values(): IterableIterator<TNode>;
66+
values(): IterableIterator<TNode, BuiltinIteratorReturn>;
6767

68-
[Symbol.iterator](): IterableIterator<TNode>;
68+
[Symbol.iterator](): IterableIterator<TNode, BuiltinIteratorReturn>;
6969
}
7070

7171
interface HTMLCollectionBase {
72-
[Symbol.iterator](): IterableIterator<Element>;
72+
[Symbol.iterator](): IterableIterator<Element, BuiltinIteratorReturn>;
7373
}
7474

7575
interface HTMLCollectionOf<T extends Element> {
76-
[Symbol.iterator](): IterableIterator<T>;
76+
[Symbol.iterator](): IterableIterator<T, BuiltinIteratorReturn>;
7777
}
7878

7979
interface FormData {
8080
/**
8181
* Returns an array of key, value pairs for every entry in the list
8282
*/
83-
entries(): IterableIterator<[string, string | File]>;
83+
entries(): IterableIterator<[string, string | File], BuiltinIteratorReturn>;
8484
/**
8585
* Returns a list of keys in the list
8686
*/
87-
keys(): IterableIterator<string>;
87+
keys(): IterableIterator<string, BuiltinIteratorReturn>;
8888
/**
8989
* Returns a list of values in the list
9090
*/
91-
values(): IterableIterator<string | File>;
91+
values(): IterableIterator<string | File, BuiltinIteratorReturn>;
9292

93-
[Symbol.iterator](): IterableIterator<string | File>;
93+
[Symbol.iterator](): IterableIterator<string | File, BuiltinIteratorReturn>;
9494
}
9595

9696
interface URLSearchParams {
9797
/**
9898
* Returns an array of key, value pairs for every entry in the search params
9999
*/
100-
entries(): IterableIterator<[string, string]>;
100+
entries(): IterableIterator<[string, string], BuiltinIteratorReturn>;
101101
/**
102102
* Returns a list of keys in the search params
103103
*/
104-
keys(): IterableIterator<string>;
104+
keys(): IterableIterator<string, BuiltinIteratorReturn>;
105105
/**
106106
* Returns a list of values in the search params
107107
*/
108-
values(): IterableIterator<string>;
108+
values(): IterableIterator<string, BuiltinIteratorReturn>;
109109
/**
110110
* iterate over key/value pairs
111111
*/
112-
[Symbol.iterator](): IterableIterator<[string, string]>;
112+
[Symbol.iterator](): IterableIterator<[string, string], BuiltinIteratorReturn>;
113113
}

src/lib/es2015.generator.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference lib="es2015.iterable" />
22

3-
interface Generator<T = unknown, TReturn = any, TNext = unknown> extends Iterator<T, TReturn, TNext> {
3+
interface Generator<T = unknown, TReturn = any, TNext = any> extends Iterator<T, TReturn, TNext> {
44
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
55
next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
66
return(value: TReturn): IteratorResult<T, TReturn>;

0 commit comments

Comments
 (0)