6 ms·
IntelliJ will detect cases like that, yes. But it is difficult and slow to get IntelliJ to inspect your whole project like `tsc` does. With PHPStan or such tool
by DCoder 7y ago
IntelliJ will detect cases like that, yes. But it is difficult and slow to get IntelliJ to inspect your whole project like `tsc` does. With PHPStan or such tools you can do that more easily, but they still have interop problems due to non-standard annotation syntax. Having native support for such type expressions would be much better.
ES6 has Map and Array, which are perfectly sufficient and distinguishable from each other. PHP core only has array() which tries to do everything. You can use array() to build a collection or an associative array and you cannot force it to only behave as one of those. Even Zend's PHP certification contains questions about what happens if you try to push a value into an array that uses associative keys. This is a joke.
I prefer React over Angular as well, but interactivity was not on my list of goals. I want a template syntax that combines valid markup, escaping by default, and TSX-style typechecking. Basically, I want XHP [0]. There is no other template engine for PHP that validates "values passed into this template" against "values used in this template" like TSX can, and no engine that ensures you're generating valid XML/HTML markup. I certainly agree that this is far less important than powerful types, but hey, one can dream :)
[0]: https://github.com/hhvm/xhp-lib https://github.com/hhvm/xhp-lib
- simion314 7y ago>ES6 has Map and Array, Bue ES6 is new, I never seen APIs that use Map , I often had to use an Object as dictionary and had to Google how to properly do it not to get extra keys and values from the Object.prototype. I am not trying to say that PHP is better then TS, but as far as type safety my PHP code with PHPDoc is better type checked then JS code with JSDoc (we are using ES5). I don't have experience with PHP rendering, but I assume you only have to escape unsafe input, don't have to escape markuup, have you tried twig, is it not safe https://twig.symfony.com/doc/2.x/filters/escape.html https://twig.symfony.com/doc/2.x/filters/escape.html ? I admit I like rendering with react, but I admit that reading a twig template is much simpler then reading JSX code (but I am condemned to use angular :-( ).