Skip to content

Pipeline Operator but for Generic Types #35712

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

Closed
5 tasks done
hazae41 opened this issue Dec 16, 2019 · 5 comments
Closed
5 tasks done

Pipeline Operator but for Generic Types #35712

hazae41 opened this issue Dec 16, 2019 · 5 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@hazae41
Copy link

hazae41 commented Dec 16, 2019

Search Terms

pipeline operator
generic types

Suggestion

A pipeline operator but for generic types

Use Cases

This would be less ugly and more readable

Examples

The following

Promise<Signed<Message<String>>>

would become

Promise of Signed of Message of String

On an interface

interface Duck {
    quack(): Promise of String;
}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@jcalz
Copy link
Contributor

jcalz commented Dec 18, 2019

Near-duplicate of #34165

@dragomirtitian
Copy link
Contributor

dragomirtitian commented Dec 18, 2019

Similarly to #34165 I find the readability claim debatable.

Also what happens with generics with multiple type parameters ? would you use G of T1 and T2 ? How would you disambiguate something like G1 of G2 and T1 and T2 ? Is that G1<G2<T1, T2>> or G1<G2<T1>, T2>? While the angle brackets are not the prettiest bit of syntax they do make it clear where one type ends and the other continues.

@hazae41
Copy link
Author

hazae41 commented Dec 18, 2019

Promise of String
Promise of (String and number)

@jcalz
Copy link
Contributor

jcalz commented Dec 18, 2019

Parentheses are too close to angle brackets for my taste; no human being uses parentheses or angle brackets to communicate. Instead of punctuation we should use a keyword to signify where a generic parameter list ends. Since reusing existing keywords is preferable to coining new ones (and helps the environment), a good one to use for this would be finally, which does a good job of signaling the end of something. And instead of and, a new keyword, we could re-use with, which is just sitting around gathering dust anyway. So: that means we can turn the completely incomprehensible

Pick<Map<string, Promise<number>>, "get">

into the human-friendly

Pick of Map of string with Promise of number finally finally "get" finally

:trollface:

@RyanCavanaugh RyanCavanaugh added Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript labels Dec 20, 2019
@RyanCavanaugh
Copy link
Member

@jcalz 😬

We're extremely conservative around adding syntax to the type space; new syntax needs to have very concrete upsides

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants