5 ms·
Polymer is my favourite front end framework. I hope it doesn't start forcing developers to use TypeScript because then I'd have to stop using Polymer. TypeScri
by jondubois 9y ago
Polymer is my favourite front end framework. I hope it doesn't start forcing developers to use TypeScript because then I'd have to stop using Polymer.
TypeScript is not suitable for building the vast majority of web UIs; it just makes things way more complicated (with the added build step, source-mapping issues, missing type definitions, outdated type definitions...) and adds no value beyond improved code completion and compiler warnings (and those two are conveniences at best).
Web applications are centred around APIs. APIs use JSON... JSON doesn't have types; so already there is an obvious impedance mismatch!
It makes no sense at all whatsoever that the front end logic should be more strict than the API!
As far as the front end is concerned, the API is the one source of truth; so unless you're willing to go back to the old days of SOAP and also start adding type annotations to your transport protocol then it makes no sense whatsoever to use TypeScript.
The main exception I can think of are web-based games; in this case it's possible that most of the complexity is actually on the front end itself (and not in the data integration aspect).
- hazza1 9y agoIn my experience giving your JSON API type information is one of the most beneficial things you can do to your web codebase.
- jondubois 9y agoTo some extent, but there is a difference between giving each object a type property (which is open to interpretation by the client app) vs forcing the client to adhere to rigid type definitions/constraints (which make it more difficult for the client to actually use the API). Developers who have used SOAP before will remember what that's like.
- ascorbic 9y agoThe client has to adhere to the shape of the JSON that the API is generating anyway. Defining those types just makes it easier to avoid mistakes. There's no reason that need to be any more rigid than the API would otherwise be.
- jondubois 9y agoBut the schema can change over time with different API versions. So you need different schemas on the front end for different versions of the API? It just seems like a lot of hassle when ultimately all you need to do is get a string property from the API and put it in a textbox.
- bitoneill 9y agoMicrosoft addressed this and says Typescript is most beneficial to manage large code bases
- jondubois 9y agoI've worked with TypeScript on large code bases. I found that the compile step becomes really slow and it slows down the debug cycle. On my last large project, I had to wait 10 to 15 seconds for the code to build every time I saved the file (and yes the compilation step was optimized to only include relevant code; a large number of dependencies don't help). So every time I made a change to the code to check something, I had to wait... You can't use console.log() to quickly check stuff anymore; the compile overhead is so significant that you're forced to pull up the debugger and manually step through the relevant code every single time you want to check something (you want to get as much info as possible from each debug cycle because it's so slow). When writing plain JavaScript, I only pull up the debugger when it's a particularly difficult bug (e.g. a race condition). For most bugs, I can get all the information I need with just a couple of calls to console.log() in my code. The debugger is just unwieldy.
- bitoneill 9y agoI used to be a c++ dev so a 15 sec compile time doesn't seem that bad. But what if you're compiler told you what was wrong faster than your console.log() could help you find it. I think is a trade off a lot of people want to make.
- 9y ago
- hazza1 9y agoTypescript is as rigid as you want it to be, you're free to loosen the types as your api demands. It really is nowhere near as heavyweight as SOAP.
- ascorbic 9y agoThis. It's also simple to generate JSON Schema from TypeScript types (and vice versa).
- tabeth 9y agoIt may be true that JSON inherently doesn't have types, however unless your backend generates random JSON for your front end to consume, specifying types for the JSON that various endpoints return is extremely helpful.
- bitoneill 9y ago> It makes no sense at all whatsoever that the front end logic should be more strict than the API! It does to people who appreciate type information. To each his own. I can see the appeal of dynamic typing but I am pretty sure obvious errors (obvious if the compiler has type info) go uncaught.
- ergo14 9y agoPolymer will not require you to use TS - it just provides you with a way to use it if you want.