I used to be a snob about various technologies. Two decades ago, I hated doing web development with JavaScript, dealing with browser quirks and what felt like deficiencies in the base standard and browser client libraries. It felt like you couldn't write simple, safe and predictable code, especially without relying on a third party framework or library.
However, much has changed and I genuinely enjoy it now. I still often prefer to write code without third-party libraries or frameworks if I can afford to, but I have increasingly come to rely on TypeScript. I value type checking a lot, especially as projects grow and APIs evolve. Managing types explicitly entails more work earlier on, but it also helps spare me from silly bugs and saves me time during refactoring or when revisiting code I wrote a while ago.
TypeScript works by transcompiling TypeScript (in .ts files) into pure JavaScript. Some of my favourite features include:
- getting to set language standard targets in configuration. E.g. setting your target to "es2016" will mean the generated JavaScript will down-compile newer syntax into syntax that exists in ECMAScript 2016. (Note: this doesn't polyfill API functionality!)
- easily defining interface types for simple objects with fixed property names
There's some effort to promote a native static type system in future ECMAScript, like this proposal: https://github.com/tc39/proposal-type-annotations. I hope for this friendlier future.
Keine Kommentare:
Kommentar veröffentlichen