Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@benny123tw
Copy link
Contributor

Description

This PR fixes a type inference issue described in Issue #47. When chaining methods like map on a PInstance, the type resolved by await has been erroneously inferred as never, even though the runtime value is correct.

The Issue

The problem also affects direct awaits like await PInstance([1, 2]). On investigation, the cause was tracked to the custom then method implementation in PInstance. The current then method does not include a full generic signature matching that of the native Promise.then, which prevents TypeScript from properly inferring the awaited type.

The Fix

This PR updates the then method to include all the necessary generics and to strictly align with the native Promise interface. With this change, awaiting a PInstance will correctly resolve to Awaited<T>[] instead of never, which fixes the type inference issue.

Linked Issues

try resolves #47

Additional context

I'm not completely sure about the reasoning behind that design choice, so I would appreciate some clarification on whether this change aligns with your original intent and the overall design goals for the library.

@antfu antfu merged commit e279526 into antfu:main Apr 2, 2025
3 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.

The return type of await p() with two .map is always never

2 participants