TS can do this: function f(x: string): string; function f(x: boolean): boolean; function f(x) { return x; } let y: string = f('hey');
The specific problem you're trying to solve is "output is the same as some input"?
-
-
https://twitter.com/BrandonBloom/status/925505166974918656 … Let me see if I can find a reasonable toy example.
-
Ah, is this what you meant by "mapping interface"? This is a clever trick.
-
Yah I was going to recommend the same thing with Flow https://flow.org/try/#0C4TwDgpgBAShwFcBOA7AsgQzFAvFA3gFBRQBEAzsEgJYoDmpAXFAEYD2bANhBigDTEy7LjxRMolGvQEBfANyFC3YFABmuKAB4AKs0m06APgAUAD2baAlMwAkAUW4BbCCmDbwETXESpMYPlDahrjB+DKKylAAbhicGqrGAOTC3LyJlgqExjGcelQGlkA … (assumed TS had something similar)...
-
Unfortunately the keys need to be strings, I think.
-
Here's a more fleshed out and generalized version of the same trickpic.twitter.com/QYtDTtuzZv
-
I'm not sure how to react to this. On one hand, this is an impressive solution. On the other hand, this is just needlessly complex.
-
Were you just looking to grouse and annoyed that I got in the way? ;)
- 2 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.