How Typed is Your Framework?

Rate this content
Bookmark

We are slowly getting to a point, where TypeScript-support is a must-have feature of a framework and not a nice-to-have. But this is not a simple yes or no question. Let's take a look at the different framework areas where TypeScript can help you develop quality applications.

Andreas Roth
Andreas Roth
25 min
22 Oct, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Today's Talk focused on the importance of TypeScript in preventing runtime errors and its integration with popular frameworks like Vue.js, Angular, and React. TypeScript provides error assistance and typing boundaries between components, ensuring correct usage. It also allows for the creation of generic components, leveraging TypeScript generics to define contracts between unknown properties. The Talk highlighted the use of TypeScript in various scenarios, such as working with React Node, and provided resources for further learning and exploration.

Available in Español: ¿Qué tan tipado es tu framework?

1. Introduction to TypeScript and React

Short description:

Thank you for having me. Today, I want to show you some code snippets and discuss the importance of TypeScript in preventing runtime errors. I will also talk about how typed React is compared to other frameworks. My name is Andreas, and I'm a development leader from Dresden, Germany. Since 2016, we have migrated all our projects to TypeScript and have become great fans. Many popular frameworks now offer first class TypeScript support.

♪ Thank you very much for having me. You cannot imagine how excited I am to be here today. It's fine that the slide is black, it's all good. Hello, everyone, as well to everyone who's watching remotely. I hope you're enjoying the conference.

Before I'm going to introduce myself, I want to show you some small snippets of the code and ask you one simple question. Does this look like fun to you? When we take a look at this, it looks innocent enough. We push it to production, run our code and run into this beautiful runtime error. Uncaught reference error, route is not defined. Of course, those runtime errors always show us the little line where the error happens in our code. So easy enough, we can spot that we just made a small little typo there. So, of course, we fix the typo, call it a day, push the code to production, go into the weekend, and, of course, Saturday morning, the client calls and tells us it's still not working. We ran into another runtime error.

Errors like these are exactly the reason why TypeScript has risen in popularity over the last couple of years. Because, of course, the main promises, those type of problems and errors will never appear at runtime if you're working with TypeScript. So you're going to your tech lead and convince him to convert, to migrate your complete code base all the way to TypeScript. Because maybe it's an older project and you're still working with class components and we're even using legacy APIs, like the legacy StringRefs. So as you can see, this is already TypeScript code, but they are still the same runtime error. Here we are passing a StringRef down there to the div to get a reference to the HTML node and at the string root. And we access this at the top with this.refs.root, but again with the same typo. As you can see, only because we are using TypeScript it does not guarantee that we will not run in any runtime errors. It depends on the framework, it depends on the APIs that we are using how safe we really are. And this is exactly the topic of my talk that I'm going to give to you now. How typed is React really, and how does it compare to other frameworks?

But first, I'm going to introduce myself because I guess most of you won't know me. My name is Andreas and I'm from Dresden in Germany and I'm a development leader at a small agency. And something around 2016, we started off migrating our first project to TypeScript and since then we have been great fans. So every new project that we are starting, no way we are starting with JavaScript, it has to be TypeScript or else we are out. And I guess many of you or some of you are sharing a similar journey. And this rise in popularity has led many of the popular frameworks to add a sentence like this to their documentation. We offer first class TypeScript support.

2. TypeScript in Frameworks

Short description:

TypeScript is a first class citizen in our framework. Vue.js and Angular have embraced TypeScript, offering better experiences. React, while stagnating, still benefits from TypeScript. TypeScript supports us in the basics and helps with errors and suggestions. It can also crash the build pipeline for typos. When using more features, TypeScript allows for typing boundaries between components.

TypeScript is working out of the box. First, the TypeScript is a first class citizen in our framework. Funnily enough, maybe you saw it already, yesterday they released the newest version of the React documentation as an early beta and I searched the docs and so far nothing like that is in the beta documentation, but we will see maybe it will be added at a later point in time. Maybe take a look at the popular frameworks.

A lot has changed over the last previous years. First of all, Vue.js when they announced Vue 3.0, they announced that they have completely rewritten the framework based on TypeScript and they are able to offer a much better experience than with the earlier versions of Vue. Angular as well, even if they started with TypeScript all those years ago, they started actually so early with TypeScript that TypeScript was not yet powerful enough to model all those dynamic features that the framework needs to offer its users. Sadly, on the React front, things have been a bit stagnating. But, this is not a problem at all because from the beginning, when TypeScript made the decision to directly support JSX or TSX, we never had any problems with the TypeScript support, so on that front, even if not much has changed, we can still get the benefits of TypeScript in our language.

In the following, I want to take a look at different areas of the framework that can be supported by the framework. At first, we're going to take a look at the basics. So within one component, you have this logic part where you call functions, you define variables, and you pass these logic parts to the template, and this template is then accessing those variables. But this is only the basics, so this really, it's the lowest level of types of support that a framework can offer. The minimum requirement to really be able to help us as developers is when the boundaries between components are typed as well. So the inputs, the data that is flowing into our components and the output, the events that flow out of it, they have to be type safe as well to really bring us any benefits. But let's start with the basics. First, maybe we are not even working with TypeScript, maybe we're still working with JavaScript. TypeScript can already help us in our framework of choice. Here, we maybe reinstalled the React type definitions into our project. So when we type react.use, we get an auto-complete, we get a suggestion of which functions we want to use right there. Later, we migrate our project and then, we're still in the logic part of our component, but already here, the TypeScript can support us and help us and show us errors when we made a small little typo or used a function that does not exist. When we then want to use this data, this logic in our templates, TypeScript again, wants to help us. So here, we define some number and we want to use it in the UI, in the template part and here as well, TypeScript can help us and give us the right suggestions. And as you see on the right, when we access the function that does not exist, again, we see the error in the editor. One very important part is that we don't only want to see the error in our editor because when we write code, maybe we are too fast for TypeScript in the background when it's compiling, sometimes it takes a bit, maybe you already closed your file, pushed to production or pushed to your pipeline and then we want to be able to crash the pipeline if we still have typos in our project. So the framework has to offer a possibility so that we can run the type checks with the command line tool. Luckily, because TypeScript directly supports JSX, we can just run TSC, the TypeScript compiler and have the errors crash the build pipeline. In the next step, it can get a bit more complex when we want to use more features that TypeScript is offering us. Like right here, we have our component that receives as a prop and a value x, which is either a number or a string. So of course, we cannot be sure which we got in our use case.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Building Better Websites with Remix
React Summit Remote Edition 2021React Summit Remote Edition 2021
33 min
Building Better Websites with Remix
Top Content
Remix is a new web framework from the creators of React Router that helps you build better, faster websites through a solid understanding of web fundamentals. Remix takes care of the heavy lifting like server rendering, code splitting, prefetching, and navigation and leaves you with the fun part: building something awesome!
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Too much JavaScript is getting you down? New frameworks promising no JavaScript look interesting, but you have an existing React application to maintain. What if Qwik React is your answer for faster applications startup and better user experience? Qwik React allows you to easily turn your React application into a collection of islands, which can be SSRed and delayed hydrated, and in some instances, hydration skipped altogether. And all of this in an incremental way without a rewrite.
Full Stack Documentation
JSNation 2022JSNation 2022
28 min
Full Stack Documentation
Top Content
Interactive web-based tutorials have become a staple of front end frameworks, and it's easy to see why — developers love being able to try out new tools without the hassle of installing packages or cloning repos.But in the age of full stack meta-frameworks like Next, Remix and SvelteKit, these tutorials only go so far. In this talk, we'll look at how we on the Svelte team are using cutting edge web technology to rethink how we teach each other the tools of our trade.
SolidJS: Why All the Suspense?
JSNation 2023JSNation 2023
28 min
SolidJS: Why All the Suspense?
Top Content
Solid caught the eye of the frontend community by re-popularizing reactive programming with its compelling use of Signals to render without re-renders. We've seen them adopted in the past year in everything from Preact to Angular. Signals offer a powerful set of primitives that ensure that your UI is in sync with your state independent of components. A universal language for the frontend user interface.
But what about Async? How do we manage to orchestrate data loading and mutation, server rendering, and streaming? Ryan Carniato, creator of SolidJS, takes a look at a different primitive. One that is often misunderstood but is as powerful in its use. Join him as he shows what all the Suspense is about.
From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
We all love GraphQL, but it can be daunting to get a server up and running and keep your code organized, maintainable, and testable over the long term. No more! Come watch as I go from an empty directory to a fully fledged GraphQL API in minutes flat. Plus, see how easy it is to use and create directives to clean up your code even more. You're gonna love GraphQL even more once you make things Redwood Easy!
TypeScript and React: Secrets of a Happy Marriage
React Advanced Conference 2022React Advanced Conference 2022
21 min
TypeScript and React: Secrets of a Happy Marriage
Top Content
TypeScript and React are inseparable. What's the secret to their successful union? Quite a lot of surprisingly strange code. Learn why useRef always feels weird, how to wrangle generics in custom hooks, and how union types can transform your components.

Workshops on related topic

React, TypeScript, and TDD
React Advanced Conference 2021React Advanced Conference 2021
174 min
React, TypeScript, and TDD
Top Content
Featured WorkshopFree
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
Best Practices and Advanced TypeScript Tips for React Developers
React Advanced Conference 2022React Advanced Conference 2022
148 min
Best Practices and Advanced TypeScript Tips for React Developers
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
Are you a React developer trying to get the most benefits from TypeScript? Then this is the workshop for you.In this interactive workshop, we will start at the basics and examine the pros and cons of different ways you can declare React components using TypeScript. After that we will move to more advanced concepts where we will go beyond the strict setting of TypeScript. You will learn when to use types like any, unknown and never. We will explore the use of type predicates, guards and exhaustive checking. You will learn about the built-in mapped types as well as how to create your own new type map utilities. And we will start programming in the TypeScript type system using conditional types and type inferring.
Building WebApps That Light Up the Internet with QwikCity
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Miško Hevery
Miško Hevery
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
Back to the Roots With Remix
React Summit 2023React Summit 2023
106 min
Back to the Roots With Remix
Featured Workshop
Alex Korzhikov
Pavlik Kiselev
2 authors
The modern web would be different without rich client-side applications supported by powerful frameworks: React, Angular, Vue, Lit, and many others. These frameworks rely on client-side JavaScript, which is their core. However, there are other approaches to rendering. One of them (quite old, by the way) is server-side rendering entirely without JavaScript. Let's find out if this is a good idea and how Remix can help us with it?
Prerequisites- Good understanding of JavaScript or TypeScript- It would help to have experience with React, Redux, Node.js and writing FrontEnd and BackEnd applications- Preinstall Node.js, npm- We prefer to use VSCode, but also cloud IDEs such as codesandbox (other IDEs are also ok)
Deep TypeScript Tips & Tricks
Node Congress 2024Node Congress 2024
83 min
Deep TypeScript Tips & Tricks
Top Content
Workshop
Josh Goldberg
Josh Goldberg
TypeScript has a powerful type system with all sorts of fancy features for representing wild and wacky JavaScript states. But the syntax to do so isn't always straightforward, and the error messages aren't always precise in telling you what's wrong. Let's dive into how many of TypeScript's more powerful features really work, what kinds of real-world problems they solve, and how to wrestle the type system into submission so you can write truly excellent TypeScript code.
Practice TypeScript Techniques Building React Server Components App
TypeScript Congress 2023TypeScript Congress 2023
131 min
Practice TypeScript Techniques Building React Server Components App
Workshop
Maurice de Beijer
Maurice de Beijer
In this hands-on workshop, Maurice will personally guide you through a series of exercises designed to empower you with a deep understanding of React Server Components and the power of TypeScript. Discover how to optimize your applications, improve performance, and unlock new possibilities.
 
During the workshop, you will:
- Maximize code maintainability and scalability with advanced TypeScript practices
- Unleash the performance benefits of React Server Components, surpassing traditional approaches
- Turbocharge your TypeScript with the power of Mapped Types
- Make your TypeScript types more secure with Opaque Types
- Explore the power of Template Literal Types when using Mapped Types
 
Maurice will virtually be by your side, offering comprehensive guidance and answering your questions as you navigate each exercise. By the end of the workshop, you'll have mastered React Server Components, armed with a newfound arsenal of TypeScript knowledge to supercharge your React applications.
 
Don't miss this opportunity to elevate your React expertise to new heights. Join our workshop and unlock the potential of React Server Components with TypeScript. Your apps will thank you.