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

Improve tqdm result type checking #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

andre487
Copy link

@andre487 andre487 commented Nov 1, 2023

In the current implementation return value's type of tqdm(foo) is any:

for (const item of tqdm([{x: 1, y: 2}, {x: 3, y: 4}])) {
    // item has type `any` and one doesn't have type checking when use properties of that
   item.x; // passed
   item.y; // passed
   item.foo; // passed
}

After this patch a result type will be correctly inferred from the input type:

for (const item of tqdm([{x: 1, y: 2}, {x: 3, y: 4}])) {
   item.x; // passed
   item.y; // passed
   item.foo; // error
}

@@ -24,7 +27,7 @@ export class _tqdmIterator implements Iterator<any> {
}
}

public next(): IteratorResult<boolean, any> {
public next(): IteratorResult<_tqdmIteratorResult<T>, undefined> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the correct form of IteratorResult: the first argument of the type points to the type that will be returned when we have values (done: false), the second – to the value when iterator is done (done: true).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant