Skip to content

Fix Generator's TNext type#38

Merged
jheer merged 1 commit intouwdata:mainfrom
kwonoh:patch-1
Jun 18, 2025
Merged

Fix Generator's TNext type#38
jheer merged 1 commit intouwdata:mainfrom
kwonoh:patch-1

Conversation

@kwonoh
Copy link
Contributor

@kwonoh kwonoh commented Jun 17, 2025

In the TypeScript definition:

interface Generator<T = unknown, TReturn = any, TNext = any> 

setting TNext to null can cause a typing error when strictNullChecks is enabled. For example:

error TS2763: Cannot iterate value because the 'next' method of its iterator expects type 'null', but for-of will always send 'undefined'.

288   for (const d of data) {
                      ~~~~

(from uwdata/mosaic#792 (comment))

While the strict type for TNext should technically be undefined, since this generator function does not make use of the value passed to .next(), it's more flexible to keep it as any. This is the default type and helps avoid blocking compatibility with libraries that may pass a value to .next() (even if that value is unused in this generator).

In the TypeScript definition:
```
interface Generator<T = unknown, TReturn = any, TNext = any> 
```
setting `TNext` to `null` can cause a typing error when `strictNullChecks` is enabled. For example:

```
error TS2763: Cannot iterate value because the 'next' method of its iterator expects type 'null', but for-of will always send 'undefined'.

288   for (const d of data) {
                      ~~~~
``` 
(from uwdata/mosaic#792 (comment))

While the strict type for `TNext` should technically be `undefined`, since this generator function does not make use of the value passed to `.next()`, it's more flexible to keep it as `any`. This is the default type and helps avoid blocking compatibility with libraries that may pass a value to `.next()` (even if that value is unused in this generator).
@domoritz
Copy link
Member

Makes sense.

At some point we should improve the types here so that the table is more strictly typed (we did a pretty good job with having strict types in the arrow js library).

Copy link
Member

@jheer jheer left a comment

Choose a reason for hiding this comment

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

Thanks!

@jheer jheer merged commit 95b2bb8 into uwdata:main Jun 18, 2025
2 checks passed
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.

3 participants