Inconsistency of type inference of Hack-style pipeline-operator proposal (Stage2) #46101
Labels
External
Relates to another program, environment, or user action which we cannot control.
Unactionable
There isn't something we can do with this issue
lib Update Request
This report is about tc39/proposal-pipeline-operator and especially TypeScript inference issue:
tc39/proposal-hack-pipes opened by @js-choi
Configuration Check
My compilation target is
ESNext
and my lib is: Babel REPL (which doesn't do any type-checking).https://babeljs.io/repl#?code_lz=MYewdgzgLgBAZiEMC8MAUBDAXDMBXAWwCMBTAJwBoYid9jyBKFAPhgxgGpqBuAKFEiwiGMinTZchUpWq0pjFmxgAqHv3DQYANwwAbPCTEBGPrz3koaAAa8AJAG8d-wwB9WCEGiNUApEzfUImgATL4MAL529mhOBjABHl5h_qzCZCFhkQ6xrqxoid4wfvGpQaFFDBG8Vgx8QA&presets=stage-1%2Ctypescript
You first need to select "Pipeline proposal > Hack" in the left sidebar, and then either click on evaluate or (since sometimes evaluate doesn't work) copy-paste the output code in the console.
The Babel implementation has been done by @js-choi (one of the champions of the Hack pipes proposal).
( tc39/proposal-pipeline-operator#227 (comment) )
Missing / Incorrect Definition
TC39 proposal Hack Pipeline Operator
|>
is incompatible with Grouping operator()
.Sample Code
Test Code 1:
Now we made
(f(^) |> g(^))
to be evaluated before other expressions with higher priority.I've investigated with Babel, and the transpiled result is identical, which means:
(f(^) |> g(^))
is NOT evaluated before other expressions with the rule of Grouping operator( )
.The current proposal Hack
|>
overrides the functionality of Grouping operator that has the highest precedence in JavaScript.Operator precedence
Test Code 2:
Now I have a
log
function.This behaves like identity function:
a => a
which does not affect to the original code butconsole.log(a)
in the process.Now, we want to know the evaluated value of
(f(%) |> g(%))
This should be totally fine because
(f(%) |> g(%))
must have some value of the evaluation according to:The vanilla JS code is:
and the result is:
3
Therefore,
where
(f(%) |> g(%))
==3
1 |> (f(%) |> g(%))
==
1 |> 3
???
and the evaluation value of whole
1 |> (f(%) |> g(%))
is3
therefore,
1 |> 3 == 3
I observer the current TC39 proposal (Stage2) Hack-style pipeline-operator is, since the binary-operator no longer holds mathematical consistency, impossible to infer by TypeScript.
Documentation Link
I explained this anomaly thoroughly here:
TC39/proposal-pipeline-operator Hack-style
|>
hijacks Grouping operator( )
The text was updated successfully, but these errors were encountered: