Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TReturn/TNext to Iterable et al #58243

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
138 changes: 66 additions & 72 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/compiler/commandLineParser.ts
Expand Up @@ -919,6 +919,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
Expand Up @@ -6376,6 +6376,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
Expand Up @@ -5226,7 +5226,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 @@ -7353,6 +7353,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
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
46 changes: 23 additions & 23 deletions src/lib/dom.iterable.d.ts
@@ -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
@@ -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