-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Add support for Partial Application #37973
base: main
Are you sure you want to change the base?
Conversation
It looks like you've sent a pull request to update our 'lib' files. These files aren't meant to be edited by hand, as they consist of last-known good states of the compiler and are generated from 'src'. Unless this is necessary, consider closing the pull request and sending a separate PR to update 'src'. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@typescript-bot pack this |
Hey @orta, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build. |
15ac42e
to
1c2f3c8
Compare
Excuse me, I'm not sure if this PR can still be trivially repacked. If it can, could you please have the bot repack it? As much as I love the pipeline operator, I actually wish for partial application even more. While not pretty, a pipe function can replicate a pipe operator pretty well; on the other hand, I can't stand partial application done through currying (as is common for TS functional programmers). Curried function signatures are very difficult to read and it's always ambiguous whether a curried function call returns another function or if it returns another data type. |
@alnj Sure enough if there's people enthusiastic about it! It's not trivial to rebase it, but it's not completely terrible either. I might be a bit busy during the start of this week but might have time in latter half. Feel free to message me here and push me forward again If I don't write an update here during this week. :-) |
I've started writing a project using the pipeline operator and all things considered, even though I would love to experiment with partial application I'm going to continue with the pipeline operator PR for the time being. Eventually that project will be open-source and can serve as a real-world example. Though I'm still learning TypeScript, hopefully I can make something decent. |
It might work, it might not |
I spent some time rebasing the code, but there's a couple of tests that fail. I'll check them out later. |
Conveniently evades the running-out-of-stack error in tests\cases\compiler\binderBinaryExpressionStress.ts, just like many other transformers.
Last version before f(?) form support is removed. Lots of bugfixes for partial application.
1c2f3c8
to
d9a9aef
Compare
A new version:
I will drop the support for the old function-call-like |
@typescript-bot pack this |
Hey @orta, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
PR adding partial application support to TypeScript. The proposal is currently a stage 1 proposal for EcmaScript. It "introduces a new syntax using the ? token in an argument list which allows you to partially apply an argument list to a call expression by acting as a placeholder for an argument."
This feature by itself seems pretty minor by itself, but in my opinion, it's a crucial part of pipeline operator proposal (F# variant).
New at 2021-10-04:
f~(?, 1)
-form (Syntactic marker for partial application) of partial application.f(?, 1)
-form still works but after this version, the support will be removed....
-rest argument.Testing
Playground Link
To test it in your project, add following to your package.json:
and then run
npm install
.PR state
Backlog
milestone (required)master
branchgulp runtests
locallyWhy a draft PR for stage 1 proposal?
The TypeScript officially follows EcmaScript / stage 3 proposals. However, I'm opening this draft pull request despite it being only stage 1. The partial application and pipeline proposals now are in a stage where they want people to test the features - write it in their code, find problems, test existing codebases. The usual way these would be done is through a Babel plugin, but since a few years ago, just a plain text editor with syntax highlighting is no longer the default JS development environment.
TypeScript is no longer just a build step. It's used by a significant portion of JS developers for all their development, even when prototyping new code. If the tool chain of these developers requires TypeScript, then a simple Babel plugin won't help. This means that writing TypeScript with those features is impossible without first-class support for them in TypeScript.
But then could we ask them to write just plain JS instead? It turns out that TypeScript is more and more part of normal JavaScript development process with Language Server Protocol pointing out errors in code and providing typing information. Having people encounter red squigglies and disappearing type information as soon as they use the new language feature will not count favourably to the user experience. I believe having TypeScript support for new syntax proposals as important or even more important than having a Babel plugin.
I was considering creating and upkeeping a separate fork, but that would just mean duplication of work. There's already a great infrastructure for TypeScript with playgrounds, CI, etc. With a draft PR, new features can more easily get more eyes, testers and feedback. There will eventually be issues and questions on new features for TypeScript and github.com/microsoft/TypeScript is where anyone would first look up info on partial application.
Of course, I'm not expecting merging until the proposal reaches stage 3.