Part of a new series! Feel welcome to dip in and weigh in on a past question.
Let's say I've never used TypeScript before. Can anyone give the run down of what the language does and why you prefer it? Feel free to touch on drawbacks as well.
Part of a new series! Feel welcome to dip in and weigh in on a past question.
Let's say I've never used TypeScript before. Can anyone give the run down of what the language does and why you prefer it? Feel free to touch on drawbacks as well.
For further actions, you may consider blocking this person and/or reporting abuse
Latest comments (48)
I wrote about this actually! (Tl;dr: Writing in TypeScript is like moving your js code from notepad to an IDE: You get refactoring, documentation, code completion and more): netanel.dev/blog/TypeScript,%20Typ...
How many of you have ever built very VERY large Web dev projects? 🤣
It's incredibly frustrating if you're only dealing with JavaScript.
Only one word.
"King of Web"
Although there is many alternative™, you can't call yourself web developer without knowing Typescript 😂
™: Hagel, Flow, dart2js, ReScript, Elm, PureScript, anything else?
Typescript union types is a blessing in disguise. Very useful when you are expecting an input which might be of different types. Say for instance, you are expecting a number as input. You don't have control over the input type, it might be a string or an int. You can declare a union type as follows:
type stringOrNumber = string | number ;
Then you can use the variable in whichever way you want, knowing fully well that what you have is a string or an integer. Say an input of array was passed, you'd get a typed error and the code won't run. Saves you a lot of time ;)
Imagine you are a new recruit on a big project written in Javascript. The task is simple:
addressofusersso it is no longer just astringbut it is an object containingzipCode,street, etc.?You then start a
Find in filessearch for the word:address.Oh no. 😐 More than 200 results have come up. Some are comments, some are related to
users, most are not. Some did not even come up as some folks made a typo:adress. You don't know until you have read the code for every occurrence of everyaddressstring. Good luck!What if someone could have given you a crutch during development time: some extra annotation to know which
address-es are related tousersand which are not? To encapsulate in some meaningfultype. To know theinterfacefor everyfunctionin the codebase... Something that you can erase so you can stay compatible with the demilitarized zone of the frozen fronts ofBrowser wars: the one allowed language:javascript.This is
TypeScript. A tool, just like yourIDEthat can save a tremendous time if you learn how to handle it. If you writeJS... Hey you already use it! Remember that nice library which your IDE immediately suggested the right object, function, parameter? Yes, the library had provided itstypingsto you. That's why it's so nice.Don't be just some
anywhen you can besomebody. UseTypeScripttoday!TypeScript is fun to read. TypeScript is not fun to write.
I see TS merely as a tool for JS, and not a superset or flavour of JS. Use it sparingly, and it is useful. Don't take it as a religion. TS has plenty of very obscure features, they sound like voodoo, it's not good.
TS: don't use everything it offers just because it is there. Same goes for JS.
Makes refactoring a hell of a lot easier.
Pitch me on JavaScript
Some comments may only be visible to logged-in visitors. Sign in to view all comments.