Skip to content

Port TypeScript PR #60321: Error on too many parameters for iterator method #16

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

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Copilot Setup Steps'

on: workflow_dispatch

jobs:
# The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot.
copilot-setup-steps:
runs-on: ubuntu-latest

# Set the permissions to the lowest permissions possible needed for your steps.
# Copilot will be given its own token for its operations.
permissions:
# If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete.
contents: read

# You can define any steps you want, and they will run before the agent starts.
# If you do not check out your code, Copilot will do this for you.
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
- uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable
- uses: ./.github/actions/setup-go
with:
cache-name: copilot-setup-steps
- run: npm install -g @playwright/[email protected]
- run: npm ci
- run: npx hereby build
14 changes: 11 additions & 3 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6065,10 +6065,18 @@ func (c *Checker) getIterationTypesOfIterableSlow(t *Type, r *IterationTypesReso
if IsTypeAny(methodType) {
return IterationTypes{c.anyType, c.anyType, c.anyType}
}
if signatures := c.getSignaturesOfType(methodType, SignatureKindCall); len(signatures) != 0 {
iteratorType := c.getIntersectionType(core.Map(signatures, c.getReturnTypeOfSignature))
return c.getIterationTypesOfIteratorWorker(iteratorType, r, errorNode, diagnosticOutput)
allSignatures := c.getSignaturesOfType(methodType, SignatureKindCall)
validSignatures := core.Filter(allSignatures, func(sig *Signature) bool {
return c.getMinArgumentCount(sig) == 0
})
if len(validSignatures) == 0 {
if errorNode != nil && len(allSignatures) > 0 {
c.checkTypeAssignableTo(t, r.getGlobalIterableType(), errorNode, nil /*headMessage*/)
}
return IterationTypes{}
}
iteratorType := c.getIntersectionType(core.Map(validSignatures, c.getReturnTypeOfSignature))
return c.getIterationTypesOfIteratorWorker(iteratorType, r, errorNode, diagnosticOutput)
}
return IterationTypes{}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
asyncIteratorExtraParameters.ts(11,27): error TS2322: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' is not assignable to type 'AsyncIterable<T, TReturn, TNext>'.
Types of property '[Symbol.asyncIterator]' are incompatible.
Type '(_: number) => AsyncGenerator<number, void, unknown>' is not assignable to type '() => AsyncIterator<T, TReturn, TNext>'.
Target signature provides too few arguments. Expected 1 or more, but got 0.
asyncIteratorExtraParameters.ts(11,27): error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.
asyncIteratorExtraParameters.ts(13,12): error TS2322: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' is not assignable to type 'AsyncIterable<T, TReturn, TNext>'.
Types of property '[Symbol.asyncIterator]' are incompatible.
Type '(_: number) => AsyncGenerator<number, void, unknown>' is not assignable to type '() => AsyncIterator<T, TReturn, TNext>'.
Target signature provides too few arguments. Expected 1 or more, but got 0.
asyncIteratorExtraParameters.ts(13,12): error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.


==== asyncIteratorExtraParameters.ts (4 errors) ====
// https://github.com/microsoft/TypeScript/issues/57130
const iter = {
async *[Symbol.asyncIterator](_: number) {
yield 0;
}
};

declare function g(...args: any): any;

async function* f() {
for await (const _ of iter);
~~~~
!!! error TS2322: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' is not assignable to type 'AsyncIterable<T, TReturn, TNext>'.
!!! error TS2322: Types of property '[Symbol.asyncIterator]' are incompatible.
!!! error TS2322: Type '(_: number) => AsyncGenerator<number, void, unknown>' is not assignable to type '() => AsyncIterator<T, TReturn, TNext>'.
!!! error TS2322: Target signature provides too few arguments. Expected 1 or more, but got 0.
~~~~
!!! error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.

yield* iter;
~~~~
!!! error TS2322: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' is not assignable to type 'AsyncIterable<T, TReturn, TNext>'.
!!! error TS2322: Types of property '[Symbol.asyncIterator]' are incompatible.
!!! error TS2322: Type '(_: number) => AsyncGenerator<number, void, unknown>' is not assignable to type '() => AsyncIterator<T, TReturn, TNext>'.
!!! error TS2322: Target signature provides too few arguments. Expected 1 or more, but got 0.
~~~~
!!! error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.
}

Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
--- old.asyncIteratorExtraParameters.errors.txt
+++ new.asyncIteratorExtraParameters.errors.txt
@@= skipped -0, +0 lines =@@
-asyncIteratorExtraParameters.ts(11,27): error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.
-asyncIteratorExtraParameters.ts(13,12): error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.
-
-
+asyncIteratorExtraParameters.ts(11,27): error TS2322: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' is not assignable to type 'AsyncIterable<T, TReturn, TNext>'.
+ Types of property '[Symbol.asyncIterator]' are incompatible.
+ Type '(_: number) => AsyncGenerator<number, void, unknown>' is not assignable to type '() => AsyncIterator<T, TReturn, TNext>'.
+ Target signature provides too few arguments. Expected 1 or more, but got 0.
asyncIteratorExtraParameters.ts(11,27): error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.
+asyncIteratorExtraParameters.ts(13,12): error TS2322: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' is not assignable to type 'AsyncIterable<T, TReturn, TNext>'.
+ Types of property '[Symbol.asyncIterator]' are incompatible.
+ Type '(_: number) => AsyncGenerator<number, void, unknown>' is not assignable to type '() => AsyncIterator<T, TReturn, TNext>'.
+ Target signature provides too few arguments. Expected 1 or more, but got 0.
asyncIteratorExtraParameters.ts(13,12): error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.


-==== asyncIteratorExtraParameters.ts (2 errors) ====
- // https://github.com/microsoft/TypeScript/issues/57130
- const iter = {
- async *[Symbol.asyncIterator](_: number) {
- yield 0;
- }
- };
-
- declare function g(...args: any): any;
-
- async function* f() {
- for await (const _ of iter);
- ~~~~
-!!! error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.
+==== asyncIteratorExtraParameters.ts (4 errors) ====
// https://github.com/microsoft/TypeScript/issues/57130
const iter = {
async *[Symbol.asyncIterator](_: number) {
@@= skipped -14, +22 lines =@@
async function* f() {
for await (const _ of iter);
~~~~
+!!! error TS2322: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' is not assignable to type 'AsyncIterable<T, TReturn, TNext>'.
+!!! error TS2322: Types of property '[Symbol.asyncIterator]' are incompatible.
+!!! error TS2322: Type '(_: number) => AsyncGenerator<number, void, unknown>' is not assignable to type '() => AsyncIterator<T, TReturn, TNext>'.
+!!! error TS2322: Target signature provides too few arguments. Expected 1 or more, but got 0.
+ ~~~~
!!! error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.
-!!! related TS2322 asyncIteratorExtraParameters.ts:11:27: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' is not assignable to type 'AsyncIterable<T, TReturn, TNext>'.
- Types of property '[Symbol.asyncIterator]' are incompatible.
- Type '(_: number) => AsyncGenerator<number, void, unknown>' is not assignable to type '() => AsyncIterator<T, TReturn, TNext>'.
- Target signature provides too few arguments. Expected 1 or more, but got 0.
-
- yield* iter;
- ~~~~
-!!! error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.

yield* iter;
~~~~
+!!! error TS2322: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' is not assignable to type 'AsyncIterable<T, TReturn, TNext>'.
+!!! error TS2322: Types of property '[Symbol.asyncIterator]' are incompatible.
+!!! error TS2322: Type '(_: number) => AsyncGenerator<number, void, unknown>' is not assignable to type '() => AsyncIterator<T, TReturn, TNext>'.
+!!! error TS2322: Target signature provides too few arguments. Expected 1 or more, but got 0.
+ ~~~~
!!! error TS2504: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.
-!!! related TS2322 asyncIteratorExtraParameters.ts:13:12: Type '{ [Symbol.asyncIterator](_: number): AsyncGenerator<number, void, unknown>; }' is not assignable to type 'AsyncIterable<T, TReturn, TNext>'.
- Types of property '[Symbol.asyncIterator]' are incompatible.
- Type '(_: number) => AsyncGenerator<number, void, unknown>' is not assignable to type '() => AsyncIterator<T, TReturn, TNext>'.
- Target signature provides too few arguments. Expected 1 or more, but got 0.
- }
-
+<no content>
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
iteratorExtraParameters.ts(11,21): error TS2322: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' is not assignable to type 'Iterable<T, TReturn, TNext>'.
Types of property '[Symbol.iterator]' are incompatible.
Type '(_: number) => Generator<number, void, unknown>' is not assignable to type '() => Iterator<T, TReturn, TNext>'.
Target signature provides too few arguments. Expected 1 or more, but got 0.
iteratorExtraParameters.ts(11,21): error TS2488: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' must have a '[Symbol.iterator]()' method that returns an iterator.
iteratorExtraParameters.ts(13,12): error TS2322: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' is not assignable to type 'Iterable<T, TReturn, TNext>'.
Types of property '[Symbol.iterator]' are incompatible.
Type '(_: number) => Generator<number, void, unknown>' is not assignable to type '() => Iterator<T, TReturn, TNext>'.
Target signature provides too few arguments. Expected 1 or more, but got 0.
iteratorExtraParameters.ts(13,12): error TS2488: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' must have a '[Symbol.iterator]()' method that returns an iterator.


==== iteratorExtraParameters.ts (4 errors) ====
// https://github.com/microsoft/TypeScript/issues/57130
const iter = {
*[Symbol.iterator](_: number) {
yield 0;
}
};

declare function g(...args: any): any;

function* f() {
for (const _ of iter);
~~~~
!!! error TS2322: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' is not assignable to type 'Iterable<T, TReturn, TNext>'.
!!! error TS2322: Types of property '[Symbol.iterator]' are incompatible.
!!! error TS2322: Type '(_: number) => Generator<number, void, unknown>' is not assignable to type '() => Iterator<T, TReturn, TNext>'.
!!! error TS2322: Target signature provides too few arguments. Expected 1 or more, but got 0.
~~~~
!!! error TS2488: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' must have a '[Symbol.iterator]()' method that returns an iterator.

yield* iter;
~~~~
!!! error TS2322: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' is not assignable to type 'Iterable<T, TReturn, TNext>'.
!!! error TS2322: Types of property '[Symbol.iterator]' are incompatible.
!!! error TS2322: Type '(_: number) => Generator<number, void, unknown>' is not assignable to type '() => Iterator<T, TReturn, TNext>'.
!!! error TS2322: Target signature provides too few arguments. Expected 1 or more, but got 0.
~~~~
!!! error TS2488: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' must have a '[Symbol.iterator]()' method that returns an iterator.

[...iter]

g(...iter);
}

Loading