Introduction to TypeScript with Vue.js 3 — Transcript

Transcript of the free Vue.js lesson Introduction to TypeScript with Vue.js 3watch the video lesson.

js 3. I'm super excited to be guiding you through learning how to combine the type safety of TypeScript with the reactivity of Vue. So let's get to it. First off, what are some advantages of using TypeScript with Vue?

I mean, Vue's already pretty great. Why in the world would someone want to mix it up with TypeScript? js 3 library is actually written in TypeScript. So in my opinion, that's a pretty good indication that TypeScript has some value to add.

Secondly, a type system like TypeScript, which provides so-called type safety, can detect many common errors via static analysis at build time. Plus, it can even make us aware of such errors in real time as we're typing in our IDEs. This means that there's less of a chance of errors popping up while the application is running in the browser, or in other words, at runtime. This is similar to tools like ESLint for JavaScript applications, but is more thorough due to the detailed information it has about the program's types.

Now, that's not to say that TypeScript replaces ESLint, but just that they perform some of the same functions. But certainly not all. In fact, they're a great pair to work with together. Next, that same type safety also allows us to refactor code in large-scale applications with more confidence and less risk.

This is because the errors that are caused by our refactoring are more likely to be caught in the IDE or at build time instead of when the application makes it to the end user's browser. Finally, TypeScript also improves the developer experience with type-based autocompletion in your IDE that can be much more focused and precise than autocompletion in plain old JavaScript projects. And honestly, even when you're working in a JavaScript project, Vue's type declarations that come packaged with the framework can even help you out as well. But if you're using TypeScript yourself, Your IDE's autocompletion can be just as knowledgeable about your project's code as it is about the Vue framework.

Okay, all that sounds pretty great, right? But are there any cases when you would not want to use TypeScript? And I think the answer to that is yes. For instance, you probably don't want to start with TypeScript if you're just starting out with Vue.

Learning the additional syntaxes and principles that TypeScript adds would just be a distraction. So, if you're new to Vue, I suggest starting out with our course, Vue JS3 Fundamentals, with the Composition API. I've left a link for it in the description below. Also, when you're building a small application or a prototype, it might not be worth the extra effort that it takes.

to define custom types and other such details that are involved with TypeScript development. Thirdly, it only really makes sense to use TypeScript when you're part of a team that's all on board with the technology. If you have colleagues that aren't comfortable with it, then obviously the added friction will probably cause more harm than good. Furthermore, if you are a solo developer, the benefit of types is diminished just a bit.

As you've naturally stored some of that type information in your head already, you just didn't realize it. However, with larger projects that require larger cognitive loads, even solo devs can benefit from TypeScript. Lastly, if you just aren't comfortable using TypeScript yet, then I say don't use TypeScript. I know I was uncomfortable with TypeScript for quite a while and felt somewhat guilty because of it.

However, I've been plenty productive with plain old JavaScript for many years, and maybe you have too. But, since you're watching this course, I assume you're at least ready to get your feet wet. So, take it one step at a time, and just like it was for me, I think the more you use TypeScript, the more you can look past the added syntax to see the benefits. Alright.

If you think working with TypeScript and Vue is the right fit for you, then I invite you to follow along with me as we build a simple journal application together. The app will allow us to record our thoughts and select an emoji for how we're feeling. Along the way, we'll get hands-on practice working within a real application, doing things like using TypeScript in single file components, typing our components' props and events, typing reactive data, and so much more.