Sunday, September 24

Tag: TypeScript

Web Tricks

Using Create React App v2 and TypeScript

Now that Create React App v2 is out, official TypeScript support comes with it. This is an exciting thing for JavaScript users that use TypeScript. TypeScript is a powerful tool that helps us write safer and self-documenting code. We can catch bugs faster with TypeScript. Many people have opinions about TypeScript, good and bad, but it's a good idea to give it a chance. For this article, we'll focus on getting a Create React App up with TypeScript and we'll do a larger project where we use TypeScript and React together in a future article.   Starting a TypeScript Create React App This is the easiest part! npx create-react-app my-typescript-app --typescript What packages does the --typescript flag get us and what changes does it make? The TypeScript Additions The --type...
CSS Tricks

Understanding why Semantic HTML is important, as told by TypeScript

What a great technological analogy by Mandy Michael. A reminder that TypeScript... makes use of static typing so, for example, you can give your variables a type when you write your code and then TypeScript checks the types at compile time and will throw an error if the variable is given a value of a different type. In other words, you have a variable age that you declare to be a number, the value for age has to stay a number otherwise TypeScript will yell at you. That type checking is a valuable thing that helps thwart bugs and keep code robust. This is the same with HTML. If you use the <div> everywhere, you aren’t making the most of language. Because of this it’s important that you actively choose what the right element is and don’t just use the default <div>. And hey, i...
Web Tricks

3 Useful TypeScript Tips for Angular

  These are the 3 tips I found pretty handy while working with Typescript: Eliminating the need to import interfaces Making all interface properties optional Stop throwing me error, I know what I'm doing Though I discovered these while working with Angular application, but all tips are not Angular specific, it's just Typescript. Eliminating the need to import interfaces I like interfaces. However, I don't like to import them everytime. Although Visual Studio Code has auto-import feature, I don't like my source files been "polluted" by multiple lines of imports - just for the purpose of strong typing. This is how we do it normally. // api.model.ts export interface Customer { id: number; name: string; } export interface User { id: number; is...