Skip to content

Commit

Permalink
Add TReturn/TNext to Iterable et al (#58243)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton authored Jul 19, 2024
1 parent f8a7913 commit 6f530cc
Show file tree
Hide file tree
Showing 163 changed files with 3,476 additions and 1,056 deletions.
135 changes: 63 additions & 72 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,16 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
description: Diagnostics.Check_for_class_properties_that_are_declared_but_not_set_in_the_constructor,
defaultValueDescription: Diagnostics.false_unless_strict_is_set,
},
{
name: "strictBuiltinIteratorReturn",
type: "boolean",
affectsSemanticDiagnostics: true,
affectsBuildInfo: true,
strictFlag: true,
category: Diagnostics.Type_Checking,
description: Diagnostics.Built_in_iterators_are_instantiated_with_a_TReturn_type_of_undefined_instead_of_any,
defaultValueDescription: Diagnostics.false_unless_strict_is_set,
},
{
name: "noImplicitThis",
type: "boolean",
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6372,6 +6372,10 @@
"code": 6719
},

"Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'.": {
"category": "Message",
"code": 6720
},
"Default catch clause variables as 'unknown' instead of 'any'.": {
"category": "Message",
"code": 6803
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5238,7 +5238,7 @@ export interface TypeChecker {
/** @internal */ createPromiseType(type: Type): Type;
/** @internal */ getPromiseType(): Type;
/** @internal */ getPromiseLikeType(): Type;
/** @internal */ getAsyncIterableType(): Type | undefined;
/** @internal */ getAnyAsyncIterableType(): Type | undefined;

/**
* Returns true if the "source" type is assignable to the "target" type.
Expand Down Expand Up @@ -7408,6 +7408,7 @@ export interface CompilerOptions {
strictBindCallApply?: boolean; // Always combine with strict property
strictNullChecks?: boolean; // Always combine with strict property
strictPropertyInitialization?: boolean; // Always combine with strict property
strictBuiltinIteratorReturn?: boolean; // Always combine with strict property
stripInternal?: boolean;
/** @deprecated */
suppressExcessPropertyErrors?: boolean;
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9006,6 +9006,12 @@ export const computedOptions = createComputedCompilerOptions({
return getStrictOptionValue(compilerOptions, "strictPropertyInitialization");
},
},
strictBuiltinIteratorReturn: {
dependencies: ["strict"],
computeValue: compilerOptions => {
return getStrictOptionValue(compilerOptions, "strictBuiltinIteratorReturn");
},
},
alwaysStrict: {
dependencies: ["strict"],
computeValue: compilerOptions => {
Expand Down Expand Up @@ -9093,6 +9099,7 @@ export type StrictOptionName =
| "strictFunctionTypes"
| "strictBindCallApply"
| "strictPropertyInitialization"
| "strictBuiltinIteratorReturn"
| "alwaysStrict"
| "useUnknownInCatchVariables";

Expand Down
3 changes: 3 additions & 0 deletions src/harness/collectionsImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class SortedMap<K, V> {
this._copyOnWrite = false;
}
}
return undefined;
}

public *values() {
Expand All @@ -154,6 +155,7 @@ export class SortedMap<K, V> {
this._copyOnWrite = false;
}
}
return undefined;
}

public *entries() {
Expand All @@ -179,6 +181,7 @@ export class SortedMap<K, V> {
this._copyOnWrite = false;
}
}
return undefined;
}

public [Symbol.iterator]() {
Expand Down
46 changes: 23 additions & 23 deletions src/lib/dom.iterable.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
/// <reference lib="dom" />

interface DOMTokenList {
[Symbol.iterator](): IterableIterator<string>;
[Symbol.iterator](): IterableIterator<string, BuiltinIteratorReturn>;
}

interface Headers {
[Symbol.iterator](): IterableIterator<[string, string]>;
[Symbol.iterator](): IterableIterator<[string, string], BuiltinIteratorReturn>;
/**
* Returns an iterator allowing to go through all key/value pairs contained in this object.
*/
entries(): IterableIterator<[string, string]>;
entries(): IterableIterator<[string, string], BuiltinIteratorReturn>;
/**
* Returns an iterator allowing to go through all keys f the key/value pairs contained in this object.
*/
keys(): IterableIterator<string>;
keys(): IterableIterator<string, BuiltinIteratorReturn>;
/**
* Returns an iterator allowing to go through all values of the key/value pairs contained in this object.
*/
values(): IterableIterator<string>;
values(): IterableIterator<string, BuiltinIteratorReturn>;
}

interface NodeList {
/**
* Returns an array of key, value pairs for every entry in the list
*/
entries(): IterableIterator<[number, Node]>;
entries(): IterableIterator<[number, Node], BuiltinIteratorReturn>;
/**
* Performs the specified action for each node in an list.
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the list.
Expand All @@ -34,21 +34,21 @@ interface NodeList {
/**
* Returns an list of keys in the list
*/
keys(): IterableIterator<number>;
keys(): IterableIterator<number, BuiltinIteratorReturn>;

/**
* Returns an list of values in the list
*/
values(): IterableIterator<Node>;
values(): IterableIterator<Node, BuiltinIteratorReturn>;

[Symbol.iterator](): IterableIterator<Node>;
[Symbol.iterator](): IterableIterator<Node, BuiltinIteratorReturn>;
}

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

/**
* Performs the specified action for each node in an list.
Expand All @@ -59,55 +59,55 @@ interface NodeListOf<TNode extends Node> {
/**
* Returns an list of keys in the list
*/
keys(): IterableIterator<number>;
keys(): IterableIterator<number, BuiltinIteratorReturn>;
/**
* Returns an list of values in the list
*/
values(): IterableIterator<TNode>;
values(): IterableIterator<TNode, BuiltinIteratorReturn>;

[Symbol.iterator](): IterableIterator<TNode>;
[Symbol.iterator](): IterableIterator<TNode, BuiltinIteratorReturn>;
}

interface HTMLCollectionBase {
[Symbol.iterator](): IterableIterator<Element>;
[Symbol.iterator](): IterableIterator<Element, BuiltinIteratorReturn>;
}

interface HTMLCollectionOf<T extends Element> {
[Symbol.iterator](): IterableIterator<T>;
[Symbol.iterator](): IterableIterator<T, BuiltinIteratorReturn>;
}

interface FormData {
/**
* Returns an array of key, value pairs for every entry in the list
*/
entries(): IterableIterator<[string, string | File]>;
entries(): IterableIterator<[string, string | File], BuiltinIteratorReturn>;
/**
* Returns a list of keys in the list
*/
keys(): IterableIterator<string>;
keys(): IterableIterator<string, BuiltinIteratorReturn>;
/**
* Returns a list of values in the list
*/
values(): IterableIterator<string | File>;
values(): IterableIterator<string | File, BuiltinIteratorReturn>;

[Symbol.iterator](): IterableIterator<string | File>;
[Symbol.iterator](): IterableIterator<string | File, BuiltinIteratorReturn>;
}

interface URLSearchParams {
/**
* Returns an array of key, value pairs for every entry in the search params
*/
entries(): IterableIterator<[string, string]>;
entries(): IterableIterator<[string, string], BuiltinIteratorReturn>;
/**
* Returns a list of keys in the search params
*/
keys(): IterableIterator<string>;
keys(): IterableIterator<string, BuiltinIteratorReturn>;
/**
* Returns a list of values in the search params
*/
values(): IterableIterator<string>;
values(): IterableIterator<string, BuiltinIteratorReturn>;
/**
* iterate over key/value pairs
*/
[Symbol.iterator](): IterableIterator<[string, string]>;
[Symbol.iterator](): IterableIterator<[string, string], BuiltinIteratorReturn>;
}
2 changes: 1 addition & 1 deletion src/lib/es2015.generator.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference lib="es2015.iterable" />

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

0 comments on commit 6f530cc

Please sign in to comment.