3 ms·
Any property access could be a getter function, and TypeScript doesn't know which properties are getters and which aren't [0]. Similarly for Proxies, anything c
by CGamesPlay 4y ago
Any property access could be a getter function, and TypeScript doesn't know which properties are getters and which aren't [0]. Similarly for Proxies, anything could be a proxy and the design goal of Proxies is that they cannot be differentiated from regular values.
But imagine that TypeScript, in addition to pure functions, also allows you to tag objects as "POD objects" or "JavaScript objects". The POD ("plain old data") objects can't be proxies or have impure getter methods, and the "pure" keyword actually means "pure if all arguments are POD objects" (this is to avoid having to write N purity overloads for an N-ary function).
You want to call a pure method from your impure method, and pass it one of your arguments. Your arguments now need to be declared to be POD objects, which means they are incompatible with the rest of your code base. This has to go all the way up... it's basically "colored functions" except it's colored objects this time, and the colors are completely incompatible (async functions can call sync functions, but impure functions can't call pure functions with impure arguments, and pure functions can't call impure functions at all).
[0] https://www.typescriptlang.org/play?#code/C4TwDgpgBAkgYgewVAvFA3gWAFBSgIwEMAnALigGdhiBLAOwHMBuHAXxxwGME6qoAzJAEFy8JKgwES5AEREAXjKisW2br2ACkAIVGJkadFAYRNRYgAoAlJOKmArsTpQA7vQAmCFwDoANgk5CYBoebwALO34mZWUmIA https://www.typescriptlang.org/play?#code/C4TwDgpgBAkgYgewVA...
- 411111111111111 4y ago> Any property access could be a getter function, and TypeScript doesn't know which properties are getters and which aren't I'm aware. That doesn't make it impossible to differentiate as Webstorm shows by coloring the bar differently for fooA vs fooB in your example. But yes, it would have to be implemented as part of that pure feature.