80: Daria Caraway on Building Considerate React Component APIs with TypeScript
Today we chat with Daria Caraway and learn how to build considerate React components with TypeScript.
For the month of february, we're chatting exclusively with Reactathon speakers.
You can hear more from Daria on this topic of developing considerate React components on the Reactathon this march.
Reactathon is a top React conference in the heart of San Francisco.
Daria and I will be there, high-fiving people and having a good time.
Get a ticket at reactathon.com.
Featuring
Links
- workday
- PropTypes
- TypeScript
- flow
- Visual Studio Code
- WebStorm
- CoffeeScript
- DefinitelyTyped
- How to Have an Amicable Breakup With A JavaScript Library | Daria Caraway | CascadiaJS 2019 on YouTube
- Intergration
- Babel: @babel/preset-typescript
- Webpack: ts-loader
- React & Webpack guide
- Forking vs Spooning — A snippet from Jafar Husain's React.js Conf 2015 talk Beyond the DOM: How Netflix plans to enhance your television experience
Transcript
[00:00:00] Michael Chan: This is React Podcast. I'm Chantastic. This is episode 80 of React Podcast. Today we chat with Daria Caraway and learn how to build considerate React components with TypeScript. For the month of February, we're chatting exclusively with Reactathon speakers. You can hear more from Daria on this topic of developing considerate React components with TypeScript on the Reactathon stage this March. Reactathon is a top React conference in the heart of San Francisco. Daria and I will be there high-fiving people and having a good time. Get your tickets at reactathon.com. Daria, welcome to React Podcast.
[00:00:48] Daria Caraway: Thank you. I'm so excited to be here.
[00:00:50] Michael Chan: It's good to have you here. Um, so this is our first time meeting, but you have a talk coming up at Reactathon, and I am— I'm super excited about it. Now, a lot of times, we end up talking with people after they've given the talk, but we have the privilege of talking with you kind of like while the talk is still being formed, while it's it's fresh and new. So tell me a little bit about um yourself and what that talk is about.
[00:01:18] Daria Caraway: Sure. Um I'm Daria. I am a software engineer at Workday um in Boulder, Colorado, and I am a full-stack developer. I leaned towards the front end for quite a long time, and now I'm leaning towards more the back end. I kind of jump around wherever I'm needed. Uh, my talk is about building considerate React component APIs with TypeScript. And basically the thesis of the talk is that TypeScript as a tool is different than other statically typed languages in that like the actual browser and your actual computer doesn't care about TypeScript, right? Like at the end of the day, your TypeScript gets compiled down to JavaScript. The browser reads it like any other JavaScript. So really it's a tool for humans and it's a tool for people. So how can we use TypeScript with that in mind to help other people instead of just like helping the compiler?
[00:02:07] Michael Chan: That's interesting. I really like this idea of the verbiage that you use here, considerate React components with TypeScript. Um, because I think that so often there is a mis- uh characterization of typed languages that they're maybe like more technical or like more advanced. Um, but it sounds like the purpose of your talk is to remind people that this is actually- it's actually primarily benefits the humans who are working on this code.
[00:02:35] Daria Caraway: Definitely. I think TypeScript for me, its biggest strength is that it's just a tool to communicate additional value to other people who are reading it. Um, so if you don't do- if you don't use that tool with like compassion in mind and be- being considerate of the people who have to read your components and read your types, then you're not really helping anyone because like I said, like the compiler doesn't really care what you're doing. The browser doesn't really care what you're doing. So yeah, it's mostly just about thinking of others when you're using TypeScript to just help help people who have to consume your code.
[00:03:07] Michael Chan: Yeah, yeah. Because like at the end of the day, it doesn't matter if it's, you know, it's Babel or like kind of artisanally handwritten compatible JavaScript or, you know, TypeScript. Um, it's all it's all the same thing at the end of the day. What are some reasons that you typically hear people talking about wanting to adopt TypeScript? Because it's been like a a really hot topic over the last, I don't know, At least 3 years, probably more.
[00:03:32] Daria Caraway: Definitely. I think what I've seen the most as an argument for why you should adopt TypeScript is the fact that it gives you compile-time type checks, it gives you compile-time bug checking, and you can get compile-time errors and not have to wait for them to make it all the way to the browser. And I think all of those reasons are are good reasons also. Um, but I think sometimes when we focus on those reasons as the main reason to adopt TypeScript, we lose sight of the fact that like it also is there to help people. You get compile-time bug checking and error checking. For me, it's it's it's almost a bonus. Um, I like to I like to use it to just help people better understand what I'm doing. And the more people that use TypeScript, the more people create this this shared understanding of how to reason about it and how to use it. And it just, it grows from there as the community gets stronger as well.
[00:04:26] Michael Chan: Now you mentioned um compile time a couple, couple times now. I know that that's a big difference between, you know, like TypeScript and then also things like Flow, which were maybe like a handful of years ago, seemed a little bit more competitive in this space. Um, what is like, what's the primary difference kind of in mindset between those two technologies?
[00:04:48] Daria Caraway: Yeah, I, I've never actually used Flow all that in depth. I've always worked at companies that just used TypeScript as kind of like the de facto language. And and I was reading that for a long time, Flow was the front runner, especially when it came to React components. Yeah. And I I think to my understanding, the difference is that Flow isn't isn't another language, right? Like you don't, the compiler doesn't compile Flow into JavaScript. All it does is just strip out all of the Flow that you've written and check against it. Whereas TypeScript will actually, with Babel, compile down into JavaScript and like it itself is another language. It has language features um similar to ES6.
[00:05:29] Michael Chan: Yeah, yeah. So, what are some of the, uh I guess, language features that are maybe new to like a JavaScript developer? So, you're like, you know, you're coming from JavaScript and you hear about this TypeScript thing. Uh like what are some of the things that are not just like kind of next-level features, like things that that um you know TC39— is that right? TC29, 39? I can never remember. Like not just the not just the next JavaScript stuff, um but stuff that's like specific to the language of TypeScript?
[00:05:59] Daria Caraway: That's an interesting question. I think for the most part, TypeScript has has always tried to keep parity with ES6. So any like great feature that you appreciate in JavaScript generally exists in TypeScript. Um and that hasn't always been the case. For a long time, the company that I worked for used CoffeeScript until ES6 came out and then didn't get onto TypeScript until TypeScript adopted some of the ES6 features. Um but it's really quite an easy transition. I I can't think of anything that stands out that I like use every day in TypeScript that wouldn't be available in JavaScript.
[00:06:31] Michael Chan: Gotcha. So I know that over the last like handful of years, um specifically with TypeScript, they've been working hard to work with the standards bodies and make sure that that TypeScript really is kind of a true superset of of JavaScript. Uh just like you said, like CoffeeScript had all these like different features that were never gonna make it into the language. And so they felt kind of very disparate and they had to make like a CoffeeScript 2 and whatnot. So, so obviously they've been working on on on parity on that front. Um, but there are additional features in the languages, in the language that actually like provide the types.
[00:07:06] Daria Caraway: Definitely.
[00:07:06] Michael Chan: So what are, what are some of those and like what is the way that a a a person, particularly one who's writing React, would interact with those most frequently?
[00:07:16] Daria Caraway: Yeah, I think, um, if if I'm understanding what you mean, like the actual typing of the language is definitely obviously the thing that doesn't exist in JavaScript. And I think for me, when, especially when building React, because React has this very like component componentized and modular mindset, the the framework is built in such a way for you to easily make reusable components. Um, but at at the end of the day, like if you make a component and people can't immediately understand how to consume it and they choose not to reuse it, then your component's not actually reusable, right? Like another team might not be able to understand it. So they go off and they make their own component that kind of does the same thing and like nobody has reused it. We all just have our one our one instance of our component. And so I think TypeScript in regards to React can really aid in the ability to make components more reusable to people that aren't necessarily you and don't necessarily have all of the context that you had when you built the component itself. And so like the APIs for how you interact with the components when you type your props can add a lot of additional information that wouldn't necessarily be there if you were just using JavaScript.
[00:08:27] Michael Chan: Interesting. So, now, I know that in in React, probably my first exposure to types was like in the very early versions of React when prop types were like built into— was built into React. Um, now, how does that— like what are the big differences for, you know, anyone who's familiar with prop types, like in kind of transitioning from, you know, prop types as this part of the library to now being part of the language?
[00:08:54] Daria Caraway: Yeah, I think that's that's a really interesting point. Um, PropTypes are basically a tool to do exactly the same thing that my talk is talking about, to build considerate React component APIs with TypeScript, right? PropTypes give you a way to add additional information to your component's API that wouldn't be there without it, um, and or without TypeScript. I think the additional benefit that you get with TypeScript is that those types can ex- in Unity throughout your entire application. So the data that's coming into your component is coming from somewhere, whether that is like a hardcoded JSON file or you're getting it from the server. And if you're able to type them from the point at which they start, that that bug catching ability that comes through will feed all the way through your code and not just like when you enter a React component.
[00:09:41] Michael Chan: Interesting. So like so so big differences is that That before, with prop types, it was just kind of isolated to the React component. So like, so you have a little bit of a guard, but they're just kind of standing at the gate of the component.
[00:09:54] Daria Caraway: Exactly.
[00:09:55] Michael Chan: Whereas, whereas with a typed language, you can actually like type, um, like that, that full data type. So like if you have a user object that you get from your, you know, JSON response, like that, you can actually have that typed through the whole system. So now other parts of your application, you know, whether they just be JavaScript or whatever, now know what that
[00:10:16] Daria Caraway: Exactly. Yeah. And I think a lot of web is communicating with a server or communicating with some external place that you don't necessarily have control over. So being able to type your objects as soon as you have control over them and feed them through the entire system just gives you another level of- like, especially when you're coming into the code, it makes the code a lot more reasonable because you don't just have to like understand the components in isolation. You can understand what objects are flowing through in the actual data model of the entire application.
[00:10:46] Michael Chan: Interesting. So, now what is the- like, so, what's the language construct for that? Like, is it like- what do you call those in TypeScript?
[00:10:56] Daria Caraway: That's a good question.
[00:10:57] Michael Chan: Or like what- sorry. Like what- what do you use in TypeScript to actually like create those things in a shareable way? Like is it just like an object or how does that all work?
[00:11:07] Daria Caraway: Gotcha. Um, so it can work in a couple different ways. I think a lot of times when you're consuming third-party libraries, they'll create typings files for you basically. So you can ingest those typing files and, um, run them through like your TypeScript compiler. So TypeScript can understand it. The other way is like, so when it comes to React components, especially that you're building, um, I like to use like interfaces and so I guess I'm not totally sure what you're asking, but- Oh, sorry. Yeah, yeah, yeah.
[00:11:37] Michael Chan: No, I think that the interfaces sounds, it sounds about right.
[00:11:41] Daria Caraway: Okay.
[00:11:41] Michael Chan: Because that's like something that you can share between, uh, like between things. Totally.
[00:11:47] Daria Caraway: Yeah, yeah, yeah. So you can basically, like, you write your types as code and in very similar to any other type language, you can- TypeScript has this concept of types, so you can actually create a declared type. Um, you also have things like interfaces to help you create like um the contract for what a particular object will be. Okay. And then you have like all of your more primitive types like strings and and numbers, I guess, is an interesting primitive type. But um and you can use these primitive types to build up like object types and they don't always have to be interfaces, but I I like using interfaces because it allows you to share them very easily throughout different parts of
[00:12:26] Michael Chan: Interesting. Interesting. So there's mechanisms in place where you could be able to just kind of put that stuff like, I guess, inline for a lack of a better term, like right in your component as if they were prop types. But if you want those advantages that you were talking about before, defining interfaces allows you to say like this function expects this interface and this component expects this interface and et cetera.
[00:12:49] Daria Caraway: Definitely. Yeah. You can type everything inline. Um, and and that can be useful and like all primitive types. For the most part are usually typed inline. But if you have like a more complex object and you're trying to communicate what exactly is held inside of that object and it's being passed through a type, you can either create a type for that object or you can use interfaces. And sometimes I see them used interchangeably as well.
[00:13:12] Michael Chan: Interesting. Now this might be a dumb question, but like if let's say you have an interface for some clump of data that you get in JSON right now. When you're writing your components, do they need to know about every single piece of that interface? Or can you have an interface and it just implements part of that interface?
[00:13:32] Daria Caraway: Yeah. So, um, TypeScript does have like, um, inheritance of sorts. So you can like compose React components by having, um, like a base interface that inherits from another interface. Um, similarly, that similar to what you can do with Like classes, um, but you can- TypeScript also has a lot of kind of unique features that are different that I've seen to most statically typed languages because it's all kind of made up, if that makes sense. Like it's all sitting on top of JavaScript. It has a lot of, um, what they call advanced or utility types that allow you to more specifically type JavaScript objects. So for example, um, if you have an interface that represents a JavaScript object, you can use um a type called partial that indicates that the type that you're passing through to the React component is just a piece of this particular interface. And and partial is a little bit- it doesn't always communicate great things to the people consuming them because it doesn't tell you which parts of the object are being passed through. Sure. So that's that's kind of one of those situations where like the compiler's gonna pass But you're not really helping anyone because all you've told the consumer is that it's probably some set of this set of properties and like some of them might not be required, but I'm not telling you which ones. Um, so TypeScript also has some utility types that allows you to better define define types in that situation. For example, they have a Pick type. So you can say this object is what I'm gonna say, a Pick of this other object and it it only has this property, this property, and this property.
[00:15:16] Michael Chan: Oh, fascinating.
[00:15:17] Daria Caraway: So you're like explicitly telling the consumer that it's a subset of this object, but here are the properties that it's going to have. Um, so you can use these advanced types in a way that doesn't exist that I've seen in like a Java or a C++.
[00:15:32] Michael Chan: Sure.
[00:15:33] Daria Caraway: Um, but at the same time, you can also use them to get yourself in a little bit of trouble where like, again, the compiler will compile, uh, but you're not, you're not providing any additional useful information to the consumer.
[00:15:45] Michael Chan: Yeah. And that it's interesting that you mentioned that because it seems like one of the reasons that types kind of got a bad rap is because of Java, Java, Java, Java, the Java, and, um, and kind of how like strict or aggressive it was about the type system. But it sounds like because of that relationship between TypeScript and JavaScript, which is an extremely fuzzy language, um, that they've they've allowed you some affordances to still like type, but maybe allow you to kind of have some squishy boundaries around those types.
[00:16:21] Daria Caraway: Yeah, that that's something really interesting to point out. Um, TypeScript can be as strict or as fuzzy as you want it to be. And and so, this is another aspect of why I think it's a tool-driven towards humans is that if you don't have a shared understanding of like how strict you are or how fuzzy you are, you're not really like adding value if another person can't immediately identify what you were trying to- Sure. Like what your intention was with the typing. Um TypeScript allows you to do things like type it as any. So, um, which basically just means I don't care what type this is, treat it as anything. You can assign it as anything, you can change it, it doesn't really matter to me. And and it's interesting for me because I think in some cases, um I I I treat TypeScript a little bit like documentation in that there's that saying that like bad documentation or wrong documentation is worse than no documentation.
[00:17:16] Michael Chan: Yeah.
[00:17:17] Daria Caraway: And I I feel kind of similarly about TypeScript because if you have like a type that's wrong in some cases or like quote unquote bad, it can be very misleading to someone who is like responsible for debugging your code or refactoring your code. It can take you down this path that that makes no sense because you're expecting the type to be one thing, but in reality it's not. And so any is kind of this way. And they also have um this idea of an unknown type. So there are there are a lot of ways to get around the fact that JavaScript isn't made for this, but if you use it to your advantage and use it in a way that still adds additional information, um I I think that it's still useful whether or not you have super strict lines or kind of fuzzy lines.
[00:18:00] Michael Chan: So, now, any or unknown would be similar to just like what JavaScript is by default, right?
[00:18:05] Daria Caraway: Right. So, any is basically default JavaScript. Unknown is a little bit different in that unknown properties can only be assigned to other unknown properties. So, you're not saying this can be anything and you can change it to anything. You're saying I don't know what this is, but it probably is the same thing elsewhere as well.
[00:18:24] Michael Chan: Interesting. Now, you mentioned a lot about the the consideration of of of this way of developing and how you're able to communicate a lot without having to, you know, maintain docs, without you- kind of consumers of your components having to find and read docs. What is the experience of this? And like where does that information- how does that information get surfaced to a developer?
[00:18:49] Daria Caraway: Yeah. Um, yeah. It's very similar to documentation that like has to be updated because if it's not, a lot of times the code won't compile. So, you don't run into that problem where like the docs are out of date. Um, it can still happen again because the lines are pretty fuzzy and you can like trick TypeScript into thinking it's working. Um, but it you are forced to keep it more up to date. And where I find this super, super useful is if you're consuming a third-party library or you're consuming components that were built by another team, I don't have to go into the documentation and read about how to use it. I don't have to go into their code necessarily and read about like, what are the props? How does the component use it so that it can inform like what types of inputs I can pass to it, I can use my IDE to command-click into the object and just see right in my IDE, right in my code, um like what the component is expecting from me.
[00:19:43] Michael Chan: Are there- I know that VS Code famously has like really good TypeScript support because it's like kind of built into their whole editor experience. And obviously they they do both, they create both. Um, but what is editor support like kind of across the ecosystem? Are there some editors that have better TypeScript support than others?
[00:20:05] Daria Caraway: Yeah, that's a really good question. I think I'm I'm one of the few web developers that I've ever met that actually doesn't use VS Code. I think it's it's because uh I also work with like Java backends. So, I use WebStorm because it's it's a familiar interface to like when I have to develop in Kotlin or in Java. Um, and the TypeScript support in WebStorm also is, is phenomenal. I've never run into anything weird where my IDE like couldn't understand what was going on. Um, and it's funny too, because for a long time I worked in a codebase that was in the middle of transitioning to TypeScript. And once you get used to the ability of like command-clicking to the place and it just taking you there and having like all of the expectations, When you're in like the plain ES6 files in the same codebase, it's super frustrating when you like command-click and it takes you to the top of the file because it doesn't know where it's coming from. Um, it, it adds a lot of kind of developer benefit that, that you don't necessarily realize until you're, you're used to it.
[00:21:05] Michael Chan: Yeah, it's so true. You know, there's, there's constantly conversations happening about how to like organize your files so you can like find them easier or whatever. And I always feel kind of separated from that whole discussion because like using, using languages that are typed or, you know, even not, but using like VS Code, which has kind of an intrinsic sense of these things. Like I just jump to the, like jump to the definition from where I'm using it. Like I, I don't ever fuzzy try to find files based on their, maybe their name or not.
[00:21:35] Daria Caraway: Right. Yeah, exactly.
[00:21:37] Michael Chan: Okay. So, so, uh, VS Code has great support. Um, it sounds like, um, WebStorm, was it?
[00:21:42] Daria Caraway: Yeah.
[00:21:42] Michael Chan: Nice. So, so you mentioned Kotlin. Have you been using a lot of, um, typed languages through your career?
[00:21:48] Daria Caraway: Um, yeah, I would say so. I have like a traditional computer science background, and the first language I ever learned was C++.
[00:21:56] Michael Chan: Oh, nice.
[00:21:57] Daria Caraway: Um, and all of the languages I learned throughout college were all typed. We learned C++, and then we learned Java, and then we learned C. And it wasn't until I started working at an internship where I started using CoffeeScript. So to me, like, the idea of not having things typed was very unfamiliar and a bit, a bit not frustrating, but kind of like you're in the Wild West, I guess, like anything goes. And if it's broken, it's all your fault, but you might not find out till later. Um, so yeah, I have, I have experience with other typed languages and our, our service that I work on on the backend is, is in Kotlin, like I mentioned. So I think for me, coming from that background, TypeScript is, is a pretty easy But TypeScript, like I like I said before, also has a lot of kind of different features about it that are inherent inherently um because of the fact that it it sits as a superset of JavaScript. So if you come in from like a strictly type language background, you might also be a little confused because things aren't going to work how you think they work.
[00:23:02] Michael Chan: Interesting.
[00:23:03] Daria Caraway: You you can get yourself into these pitfalls where your your code compiles and in Kotlin, that's like a pretty good indication that what you've done is right. And that's not necessarily- You're good to go. Yeah, you're good to go. Um, there might be a runtime error, but probably not. Uh, and that is like definitely not the case with TypeScript. So again, you have to be more mindful of like the human aspect of TypeScript to really take advantage of it.
[00:23:25] Michael Chan: Interesting. Now I know that there's a lot of- you mentioned uh kind of reusable components and I'm sure that there's probably reusable types as well. Um, how does this work? You know, if you're you're in a React codebase and you want to start progressively adding some React, are there kind of like reusable types for more common patterns like, you know, like render props or like higher-order components or things of that nature? Or is that something you kind of have to figure out, you know, as you go along?
[00:23:53] Daria Caraway: Um, React in itself, when you're using the typings provided, is is pretty straightforward. Um, you can actually- something that I think is really cool with React and like the the language of it is, um, when you use the children prop coming off of like that React just gives to you, um you can type out your children. So even though like, it's kind of a cool way to say, if you pass me this child, like I'm a menu component. So I know all of my children have to be like of type menu list.
[00:24:26] Michael Chan: Okay.
[00:24:27] Daria Caraway: Um and so you can you can take advantage of like React features and add on this additional layer of TypeScript. Um as far as making them reusable, I'm not really sure, like there's no library that I know of that just has like TypeScript types that you can take because it's usually fairly straightforward and it's usually just up to whatever data model you've built. So you can definitely reuse those patterns throughout your, your own codebase.
[00:24:54] Michael Chan: In your experience, what is, um, like what's the ecosystem and the community like in, in TypeScript versus, or I guess just in general, how's it, how's that community and how well are they doing at supporting other developers using TypeScript?
[00:25:10] Daria Caraway: Yeah, uh the TypeScript community is is pretty awesome. Um it for a long time, I didn't realize that like not everyone was using TypeScript because as far as I was concerned, everything I ever had to do was fully supported. Um and it tends to change between frameworks. So Angular, for example, um is built with TypeScript. And so everything within the language is like has typed typing and TypeScript as like a first-class citizen. Um React is a little bit different because the the community isn't all sold on TypeScript yet, right? So there are definitely situations that you can get in where you want to consume a third-party library, um but the library owner is not supporting the type definitions for it. Mm. There's um a package on npm called DefinitelyTyped, which is just the place where the TypeScript community puts typings for third-party libraries. So even if a library owner isn't supporting the type definitions, there's usually somebody else who is and definitely typed, or maybe that's you because you really care about this library and you want to make sure the typings are up to date. Um, but that's definitely something else to keep in mind when you're thinking about converting to TypeScript. If you're using a lot of packages that don't have great TypeScript support, you're going to lose type safety when you go from like the boundary from their package to your package. It doesn't mean that you can't also use typings and you're free to create typings for those third-party libraries that don't necessarily have them, but you do have to be aware that you're gonna lose like some some piece of type safety when you're moving from that library to yours.
[00:26:42] Michael Chan: Interesting. So if I wanted to use a package that didn't have types and they weren't on DefinitelyTyped, let's say it's like a really small package that like nobody knows about, but I really like it. Um, what are my- so my option, my first option is like I can still use it. I can still consume it, but I kind of it's it's questionable. That part of my code is questionable. Um, is it possible to write interfaces of my own just inside my code? Yeah. That would allow me to use that in a safer way?
[00:27:10] Daria Caraway: Totally. So, you can create your own typings file for any code in your codebase. So, even if it's in npm, you can tell TypeScript to go and look for the typings for this particular package in this particular location. And that location is in your own codebase. And you've you've determined yourself to keep it up to date with with the with the releases, right? Um, that's totally possible. And it's, I've definitely done it before because you want to use a really cool select library, but they don't have typings, but you're not gonna write your own select library because they don't have typings. So you you tend to write your own typings for the pieces of the library that you care about. Okay. The pieces that you're going to interface with, because you don't have to type the entire library. When you're not using like feature X and Y. Um, but one of the downsides of doing so is that if the owner were to ever publish a new version that like completely changes the interface, um, and you're still using your own typings, uh, they're not gonna they're not gonna be right, right? And they might be a little bit misleading. So you have to be aware of that if you are maintaining your own types for for another library.
[00:28:15] Michael Chan: Because if it was if it was your code, then you would have You would know right away. Right. But as far as TypeScript's concerned, it's gonna compile because it's like, oh yeah, you defined the types and you're using those types and like it doesn't, it has no way of knowing what's underneath.
[00:28:30] Daria Caraway: Exactly. Uh, once you, once you start interfacing with JavaScript, um, TypeScript does its best to guess for what you've provided it. But at that point you've, you've told the TypeScript compiler what to expect. So if, if those are wrong, like it doesn't know any better. Cuz the, again, the computer doesn't care, right? Like it's just gonna do what you tell it to do.
[00:28:50] Michael Chan: That's awesome. So now I know that there's a lot of, um, I guess like different ideas in the frontend space. Like there's a lot of, um, languages that are specifically like languages for constructing UI. And one thing I'm always kind of curious is like, what are some of the advantages of TypeScript as a language in that space? Like where you have other languages that are just like, like, I guess like Elm. And then I know that there's like a lot of work being done by Facebook and Reason, which are like specifically like UI framework languages? Like what's gonna be the biggest benefit to using choosing something like TypeScript?
[00:29:28] Daria Caraway: I think the biggest benefit is that you still get to take advantage of the JavaScript community because they've created themselves as a superset of JavaScript. There's so many resources out there. There's so many libraries out there. The React community, for example, is so big in JavaScript. You you get to take advantage of all of that and then just also provide this additional layer that that can probably help other people along the way. Um it it's not like you go to TypeScript and like all of a sudden everything in the JavaScript realm is completely useless. Um you get to use it. And and like we said, even if it isn't supporting TypeScript, you can still choose to use it if it's super important to you. It's kind of like a a choose your own adventure of sorts when it comes to TypeScript.
[00:30:11] Michael Chan: That's awesome. Are there any like Are there any drawbacks, I guess, in your experience? Because it sounds like it's it's fairly progressive. Like you can kind of use it as much or as little as you need. You get the benefit of it sitting right on top of JavaScript. And, you know, there's there's a huge community around it supporting types. Um, it sounds like all positives to me. Uh, but what are some of the drawbacks that people experience?
[00:30:38] Daria Caraway: Yeah, I think a lot of the drawbacks that I've seen is when you have that mindset that everything is positive and just because you use TypeScript, all of your code is just like magically gonna be perfect and better. Um and that's absolutely not true. Um you still have to you still have to use it as a tool and think about how you're using that tool. Think about um what you are saying when you use that tool. And and if you're using the compiler as a standard of like what's good and what works, you're gonna miss the human standard of all of the other people that have to read your code. So you really have to approach it with this mindset of like, oh, we added types, now everything is just perfect and we don't have any bugs anymore. Shift that mindset to like, how can we just use this tool to make things a little bit better? And I think if if you're on a team where not everyone has like bought into the idea to the point where they're just using types to make the compiler happy, It, you've almost fallen into that trap where uh it might be worse because it's super misleading and and you waste a lot of time trying to like reconcile the differences between what's reality and what's happening in TypeScript. And I I think too, you can you can kind of catch yourself when you start to fall into this pit. Like I I think all TypeScript devs have probably had this moment and can relate where like you're really stuck on something and you just can't get it to work in TypeScript. And for whatever reason in that moment, like you don't understand what's happening and you can't get the TypeScript compiler to be happy. So you do something and the compiler compiles and like you have this feeling that you've tricked the compiler into working and you can like move on and you're like superior because you like tricked the computer into doing what you want. When in reality, like all you've done is trick yourself and like whoever has to come after you to read this code. So, there's there's definitely drawbacks. But I think in my experience, they're almost always drawbacks that we create for ourselves.
[00:32:41] Michael Chan: Interesting. Now, in terms of integration, um, is it is it fairly easy with today's toolset to, like, I guess, just integrate this with Babel or to, like, swap out Babel for, you know, TypeScript compiler? Um, is it pretty easy these days?
[00:32:58] Daria Caraway: Yeah. Um, if you're using Webpack, which I, I think most people probably are, um, you can just use all of the plugins to get your TypeScript to compile down into JavaScript. Um, it's another step if somehow you're like a lucky person who gets to write JavaScript that just runs as what it is. Um, I don't think that's necessarily true for a lot of people anymore because a lot of people are compiling down to ES5. Like there's a lot of people in the web community have this like conversion already happening. So, it's just another another step for it to compile down into JavaScript from TypeScript.
[00:33:30] Michael Chan: Nice. Now, I want to shift gears a little bit and talk a little bit about another talk that you've done, which is— is um I'm glad that you gave it. I was actually really happy to watch it this week. Oh, thank you. Because it's something that I feel like has been like this like process uh in the back of my head. I'm like, man, that would be a cool thing to talk about. And you gave the talk. I can't remember, man, the the name of it escapes me right now, but you can tell me. But it's about like kind of like dating front-end frameworks. Yeah. And like you you draw this amazing analogy about like dating and breakups and relationships, um, with the tools that you use to build your app. Could you remind me of the title?
[00:34:10] Daria Caraway: Yeah, it's called How to Have an Amicable Breakup with a JavaScript Library.
[00:34:14] Michael Chan: That's right. It's so good. So, how did um how did you come to want to give this talk? Like what was the experience that brought you to that that talk?
[00:34:24] Daria Caraway: Yeah. Um, I have spent most of my career um at companies that are kind of in an intermediary phase where they're either converting from JavaScript to TypeScript, they're converting from AngularJS to Angular, they're converting from AngularJS to React. Like, I I think this is this is true for a lot of the community because things happen so quickly. Um, and I was I was on a team and we were writing um a a whole new set of code in in Angular 2 and we were converting it from AngularJS. And we decided that there were all of these components out there. There's so many third-party libraries. There's so many like options. You need a select. Well, there's like 15 select libraries. Yeah. And they're all kind of similar, but like a little bit different. Um, we needed a table and there was like 20 table libraries and we had to somehow figure out how they're different, why they're useful to us. And and like half the time you pick one and then 6 months later you have to throw it away because you made a terrible decision and like something is wrong with the component that you chose. Um, and so our our team developed this this idea and it's not a new idea. It's a very common uh design pattern that is like thoroughly used throughout throughout programming. But this idea, if we wrap the libraries and we expose only the interface that our components and our um our code cares about, when we are 6 months down the road and like our lives suck because we made a terrible decision on some table, um we can just switch it. And as long as we don't touch the wrapper that we wrote that interfaces with our code, like everything just works. And I think I thought that was really powerful. And and I went to a new company and a lot of teams weren't doing this. We have our own design system called CanvasKit at Workday. And so all these teams are writing React and they're integrating with CanvasKit. And CanvasKit is is in productions, like currently being developed. So a lot of things are changing. So even if you're using like an internal library, things tend to change. Yeah. And you don't want to be that that application that's stuck in an old version because you have to go and update uh 200 buttons, for example. Um and you don't want to be that person that has to sell to your product owner like, hey, it's gonna take me 2 weeks to change the buttons to be- Yeah. Different buttons. They they do the same thing, but they're just like a little bit different. Um and so, yeah, I've been bit by this a lot and this wrapper concept of being able to quickly switch out your libraries, um, and like dump them essentially, 'cause it happens all the time. Uh, it's been really useful. So I just, I just wanted to share it with people 'cause I think it can save a lot of people a lot of time.
[00:37:08] Michael Chan: Yeah. You know, you touched on a concept there that I think a lot of people overlook when they're talking about designing their design system or using an open source framework, like, you know, Material UI or all that kind of stuff that they don't realize that they're giving up power by opting into that, right? Like, you know, when you write it yourself, like, you have complete control over that thing. And when you use a framework, it's like, now you have to open up a pull request and, like, pray that the developer who is the only person who can actually merge your pull request, like, isn't in Hawaii for the next 6 months.
[00:37:41] Daria Caraway: Right.
[00:37:41] Michael Chan: And even internally, you know, if you have multiple teams using a design framework, um, it's still subject to their decision-making process. And so, this idea that you're talking about of of of wrapping components and kind of creating your own minimal interface for it um is super important.
[00:38:01] Daria Caraway: Definitely. And and it doesn't even have to be big changes, right? Like it I've seen it happen where they're like, we don't want to call this input um label. We want to call it description, right? So then they they change like the value or the name of the thing that you're passing in. And maybe you had like put that in an object to pass in as props, um you now have to go and like update this one word to be a slightly different word. Um and it's just a huge pain. So if you can separate yourself from all of that, and again, like what you said, like give- empower yourself to have control of what your code is interacting with, um it can be, it can be really helpful.
[00:38:42] Michael Chan: Yeah. Do you feel like that improves the I guess, way that people think about interfacing with other code in general, when they can kind of get this concept of of of wrapping into their head.
[00:38:54] Daria Caraway: Yeah, I think so. It uh I think at the end of my talk, it's I say that it makes the breakups less painful or something like- it it it really does free you, um and it decouples like the library's opinions from what you want it to be. Not only are you free to change the library at will, but if they're using like like um an input pattern for their props that you're not using throughout the rest of your code, it can be really sporadic to be using that in your code because you're using this third-party library that's like dictating how you pass data into the component. Mm-hmm. And when you create this wrapper, like you can unify all of your components, third-party or internally, to have a similar a similar interface. Um that's actually kind of where my talk for Reactathon came from, is I I had this talk about how you can build these wrapper components protect you from JavaScript library breakups, but how can we on the other side of that author those wrapper component interfaces in a way that is useful for everyone? So that's kind of where the the consider it React component APIs talk came from.
[00:39:54] Michael Chan: I love that. Yeah. And it's like, so often you see this where like in a component design, like it might require some value. And I think this is kind of maybe what you're talking about. It might require some value, but like for you and your project, that's always true. Right. And so like, why always send that in if it's always gonna be true? And so you can kind of like say like, oh, it is always true. And then like, we don't even accept that as a prop anymore.
[00:40:16] Daria Caraway: Exactly. Yeah. Maybe you're using a button that has like 15 different states, but your application only ever has like 1 or 2 states. There's no reason for every developer to have to go and understand what the 15 states are so that they can pass in like the same state you're using throughout your application. And it also works like uh for for other types of design patterns. So my example in the talk in in regards to React was some components take inputs as props and some components take inputs as children. And if you're if you're favoring one version over the other, but all of a sudden you're using this library everywhere that does it this other way, um now you're just like mixing people's opinions throughout your code and they're not even your own opinion. Which makes it even more frustrating.
[00:41:02] Michael Chan: So it's actually- so it sounds like a way where you can actually reduce documentation. You can kind of go to like where the team is and instead of having to produce more documentation about mapping, you're just like, we're just gonna cut these concerns out because we don't even think about them.
[00:41:16] Daria Caraway: Right. Yeah, definitely. You can isolate what your- what your application actually needs and not worry about the 200 other like use cases that was built into this library because so many other people are using it and just use it for your one use use case. And it kind of helps with like decision fatigue. Like your developers using it don't have to figure out all the different things when they they just want it to look like all of the other ones that you're using.
[00:41:42] Michael Chan: Yeah, yeah. Do you find that it's important to have that that's a shared responsibility when you're bringing in a library? Or is it good to have someone who's kind of in charge of the connective tissue between your application and like the world at large?
[00:41:56] Daria Caraway: I've personally found that if if your whole team isn't like on board with this pattern, um then it it doesn't always work out right. Because lots of people are bringing in different third-party libraries for different reasons. If you're not all on board with this wrapper pattern, like you have it some places, you don't have it other places. It to me, different types of code is almost worse than like one type of less desirable code. Um so I've I've seen it be successful when an entire team is working together to build these interfaces for whatever libraries you have to interface with. Um, and even if you're just using one library, but you're pulling in different components, you don't wanna have to have one person who's responsible for like pulling in all of those components when-
[00:42:38] Michael Chan: Yeah.
[00:42:39] Daria Caraway: Developer B just needs like an air box or something.
[00:42:43] Michael Chan: Yeah. I heard, I've heard this, um, this concept of wrapping also described as spooning a library.
[00:42:50] Daria Caraway: Ooh.
[00:42:51] Michael Chan: So, so we're, we're accustomed to like forking a library. Library, but like you can you can spoon a library. You just kind of like you just like wrap around it a little bit, which I thought was like a great visual illustration of like what you're doing. You're like-
[00:43:03] Daria Caraway: That's awesome. That's exactly that's exactly what it is.
[00:43:06] Michael Chan: Now, one thing that I really liked um in in in that talk was the idea of um of speed dating. Uh could you tell me uh about that concept and the benefits of that? Because I thought that was so well put.
[00:43:18] Daria Caraway: Thank you. Um yeah, so speed dating in in my mind is when you your you or your team, you've decided that you need a third-party library of some sort. Um, the first time I used this speed dating concept, it was actually that same grid component or like a table component that we needed. And and there was 20 grids and um they all tell you that they're the best grid because they want you to use your grid. Um, especially like in the Angular community, a lot of the components are in libraries that you pay for. So they're all telling you that they're the best grid because they want you to use it. This is less so with the React community because it's a little bit more like open sourced. Um, but uh our our team had an idea to just basically speed date all of the all of the grids. So we loaded them into their own, like as an individual framework into, um it wasn't Storyboard, but you could definitely use Storyboard to speed date. That's something that's popular with React right now. And like isolate it in, you could use it in Storyboard, but you could also just plug it into your application. And because you have this wrapper, you should be able to plug them in, um, really quickly and just like get to know each library a little bit, get to know like, is it gonna be performant enough when I dump in 2,000 results? Or, um, does it have like the CSS, uh, theming capabilities that we want? Because we want it to look like our grid, not somebody else's grid. Right. And it just gives you the opportunity to, to learn about it. Um, and I call it speed dating 'cause it does feel like that. Like sometimes at the end you're like, this isn't the one and and you dump it away. But it can help with like future breakups because you've you've done a little bit of work up front to verify that it's gonna meet your needs.
[00:44:59] Michael Chan: Yeah. And that particularly was something that I really liked was the idea of of doing that exploratory work to to actually flesh out what you need it to do. Because you may think that like you may think you know what you want, but like this actually exposes like, oh, actually I care about this more and I'm willing to sacrifice these other things. In order to have that thing.
[00:45:20] Daria Caraway: Definitely. Yeah, and um it just it helps with like, we've all picked a library and we're like, it's the best one, like what could possibly go wrong? And then like less than a month later, you're like, this was a terrible idea. We have to pull the entire thing out now and start all over. So ideally, like if you sample enough dates, if you will, um you can get a better idea for which one you can you can have a long-term relationship with.
[00:45:46] Michael Chan: Yeah. And you know, it's, it's, it's interesting because I think like a lot of the, the, I guess, JavaScript fatigue is, is self-induced, but also, you know, things move so fast, um, including our products. Like it could be that like a month down the road, you have a new constraint that like wasn't even on the table like 30 days ago. And like, now you're like, oh crap. Well, we should have gone with the other one because that actually had that thing that we need.
[00:46:12] Daria Caraway: Yeah, that happens all the time.
[00:46:13] Michael Chan: Yeah. And so it sounds like this allows you to kind of, I guess in the same way that that interfaces and types allow you to define what your expectations are, creating these wrappers kind of allows you to do the same thing with components. We say like, this is the interface that we need. And, um, you know, like whatever we use under the hood, like that's, that's just implementation details.
[00:46:34] Daria Caraway: Definitely. Yeah. I, I think the, the two topics for these two talks, um, To me, kind of go hand in hand. Um, these wrappers I've found to be like much more useful when you're using TypeScript because you can create considerate component APIs that the rest of your team can immediately understand. And if you've created this like common sense of understanding of how you want to use TypeScript with your team, it's so much more valuable. You have control of these wrappers, you have control of how your team has agreed to use TypeScript, and it just adds so much more Um, useful, useful information to make decisions about when you're using those components.
[00:47:12] Michael Chan: Well, I love it. Thank you so much for sharing your wealth of knowledge about types and defining interfaces around components and, and the kind of practical aspects of that work. Is there anything else that you'd like to share with us as we wrap up?
[00:47:26] Daria Caraway: I don't think so. Uh, thank you so much for having me.
[00:47:29] Michael Chan: Oh my gosh.
[00:47:30] Daria Caraway: I'm so excited.
[00:47:31] Michael Chan: It's my pleasure. And I am, I mean, I loved your last talk so much. We're definitely gonna link that in the show notes. I cannot wait for this one. I'm sure it's gonna be be amazing. So how can people find you on the internet to uh kind of get these uh these nuggets of wisdom as uh you kind of discover them yourself?
[00:47:51] Daria Caraway: Yeah, I'm pretty new to the internet as a human, um like not in my life, but as a speaker and as someone who goes on podcasts. So you can follow me on Twitter @Daria Caraway. I don't post a whole ton, but I'm also trying to write more blog posts. And if you go to dariacaraway.com, I should have some blog posts up there.
[00:48:12] Michael Chan: Awesome. Well, it was a pleasure to have you. Thank you so much for your time today, Darya.
[00:48:15] Daria Caraway: Thank you so much. This was super fun.
[00:48:17] Michael Chan: For links and show notes, visit reactpodcast.com/80. If you like this show, there's a fast, free way to demonstrate your support. Leave us a review on iTunes. It's the best way for you to let me know what you think we're doing right and what we can improve. 2 to 3 minutes of your time helps us make the best show we possibly can. As always, links and show notes for all episodes are available at reactpodcast.com. This episode was edited by Mikael Delport. It was produced by Mikael Delport and Sarah Jackson at Speck, a network to help you level up in design and development. Check out spec.fm for other shows that are sure to fast-track your career. I'm your friend, Chantastic. Thanks for listening. We'll be in your ears again next week.
chantastic.fm