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

Stop using user-assignable type generics in the types of functions that don't do anything with them #337

Closed
Avaq opened this issue May 7, 2019 · 4 comments · Fixed by #374

Comments

@Avaq
Copy link
Member

Avaq commented May 7, 2019

This is an alternative to #230 made possible by the introduction of the unknown type.

See also #334 (comment).
See also #370 (comment).

@Avaq
Copy link
Member Author

Avaq commented May 20, 2019

TypeScript 3.4 introduces higher order type inference from generic functions. This might make the need for using anything but an undetermined type variable/generic unnecessary. I should do some experiments with this.

@Avaq Avaq changed the title Update typescript types to use the "unknown" type for undetermined type variables Stop using user-assignable type generics in the types of functions that don't do anything with them May 20, 2019
@Avaq
Copy link
Member Author

Avaq commented Sep 22, 2019

In response to #370 (comment)

I tried a simple thing myself, and it seems never and unknown have the same issues, but in opposite orders.

With never/undefined

latest-screenshot
latest-screenshot

Here the problem is that we're not allowed to assign anything to never (the same goes for undefined). So when we're trying to assign Future<string, never> to Future<never, number>, it breaks on the rejection branch.

With unknown

latest-screenshot

Here the problem is the other way around: we're not allowed to assign unknown to anything. So when we're trying to assign Future<string, unknown> to Future<unknown, number>, it breaks on the resolution branch.


In conclusion, it seems that neither never nor unknown possess the desired behaviour. I will continue exploring.

@Avaq
Copy link
Member Author

Avaq commented Sep 22, 2019

It seems that never has the behaviour we want, but only when chain uses a union to define the type of the left branch. The downside is that this will allow users to mix their types through usage of chain.

Avaq added a commit that referenced this issue Sep 25, 2019
- Revert #230 and reintroduce the usage of the 'never' type
- Relax the signature of chain and chainRej to allow TypeScript to
  derive types when merging a Future of a never with a Future of a
  real type. Closes #337 and closes #370.
- Move generic types closer to where they are used in the function
  signature. Closes #372 and closes #373 through supersession.

Co-authored-by: Edgar Rodriguez <edgarj.rodriguezg@gmail.com>
@Avaq Avaq closed this as completed in #374 Sep 26, 2019
@codingedgar
Copy link
Contributor

Yes i agree that neither of the types work right now.

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 a pull request may close this issue.

2 participants