TypeScript for Library Authors: Harnessing the Power of TypeScript for DX

Using real-life open-source examples, we'll explore the power of TypeScript to improve your users' experience. We'll cover best practices for library authors, as well as tips and tricks for how to take a library to the next level. This talk will cover: 


- how to leverage the type inference to provide help to your users; 

- using types to reduce the need and complexity of your documentation - for example, using function overloads, string literal types, and helper (no-op) functions; 

- setting up testing to ensure your library works (and your types do too!) with tools like tsd and expect-type; 

- treating types as an API and reducing breaking changes whilst shipping enhancements; 

- I'd draw on my experience with libraries like nuxt3, sanity-typed-queries and typed-vuex and show what we managed to do and what I'd do differently in future. 

Rate this content
Bookmark
Video Summary and Transcription
TypeScript for library authors is a topic that highlights the benefits of using TypeScript for both internal and external purposes. Internally, TypeScript enhances code quality by covering edge cases and facilitating refactoring. Externally, it serves as a form of library documentation by providing users with insights into expected function behaviors. This makes TypeScript a valuable tool for improving the developer experience. The use of tools like JSDoc and jsdocs.io can help maintain up-to-date documentation within the code, eliminating the need for separate documentation websites. Testing TypeScript types is crucial, and tools like Unbuild and API Extractor are recommended for ensuring accurate type definitions. Versioning TypeScript types is essential to prevent breaking changes in user code, and adhering to semantic versioning helps manage these changes. The concept of 'fountain of truth' in TypeScript involves allowing the language to infer return types, which reduces errors and maintains accuracy. Nuxt leverages TypeScript for better developer experience by providing automatic type detection for components and plugins. This integration ensures that developers receive accurate type information directly in their IDEs.

This talk has been presented at TypeScript Congress 2022, check out the latest edition of this JavaScript Conference.

FAQ

TypeScript types and TS doc (or JS doc) can serve as accurate, up-to-date documentation embedded directly in the code. This approach ensures users get the correct information for the version they are using without needing a separate documentation site.

Expect type and ts-expect-error are recommended for testing TypeScript types. These tools help ensure that the types are accurate and behave as expected.

Versioning TypeScript types is crucial because changes in types can break user code. Adhering to semantic versioning (semver) helps manage these changes and ensures users are aware of any potential breaking changes.

The 'fountain of truth' paradigm suggests allowing TypeScript to infer return types from the actual code, rather than manually declaring them. This approach helps ensure the types are accurate and reduces the risk of errors.

Types can be used to accurately describe the expected inputs and outputs of functions, enhancing the usability and reliability of the library. For example, using string literals instead of generic strings can provide more specific and useful information to the user.

Type inference allows TypeScript to deduce the types of variables and return values automatically. This feature is particularly useful for creating accurate and maintainable types, especially in complex libraries.

Nuxt uses TypeScript to provide automatic type detection for components, plugins, API routes, and more. This integration ensures that developers get accurate type information and support directly in their IDEs.

You can contact Daniel Rowe via email or Twitter for more information. He is also active on the Nuxt Discord server, where you can ping him directly with any questions.

TypeScript helps improve code quality by covering edge cases, facilitating refactoring, and providing accurate documentation. It offers a true-to-life representation of how libraries work, enhancing the developer experience.

The speaker is Daniel Rowe, a member of the Nuxt core team based in the northeast of the UK. He maintains several open-source packages and has a strong interest in improving developer experience.

1. Introduction to TypeScript for Library Authors#

Short description:

TypeScript for library authors offers benefits for both internal and external use. Internally, it helps improve code quality, cover edge cases, and facilitate refactoring. Externally, it provides users with an accurate understanding of how libraries work, offering a true-to-life representation of their functionality. TypeScript allows users to gain insight into libraries and understand the expected behavior of function calls.

Hello. It's a pleasure to be here today, talking about TypeScript for library authors. It's dear to my heart because I'm self interested and love using libraries with great developer experience, and I'm sure you do as well.

My name is Daniel Rowe. I'm based in the northeast of the UK, and I'm on the Nuxt core team, and I maintain a few other open source packages as well. I should say in advance, this is my perspective as we dive into TypeScript for library authors, you may have other ideas. You may have better approaches, and I'd love to hear from you if that's the case. Please do contact me, either by email or Twitter is a great way to make contact. Please. I'd love to connect later.

So, to start with, the question I'd like to pose is what's the point of TypeScript for library authors, I guess. And obviously, even if you weren't exposing your types outside of your own project, I think there would still be benefit. I certainly would find that there would be myself. I think TypeScript helps improve the code that we produce. It helps us cover edge cases. It helps us see the possible alternatives and outcomes of what we're creating. And it helps with things like refactoring, making sure we haven't left something out. Lots of huge benefits for using TypeScript internally.

But I think looking at the question of why we use TypeScript for external benefit, the key reason is truth. And I think there are a couple of different implications for this that I hope to go through today. But I think it all comes back to truth. We're allowing our users a window into how our libraries work. That window is accurate. It needs to be accurate. We're offering them an alternative to looking at our source code or reading our documentation. Something that is actually a true-to-life representation of what is happening. And that I think is one of the things that makes TypeScript so amazing, when you're using it as you consume some other library. Because you're getting insight through it. Your IDE popup is telling you something about how it works under the hood. It's telling you something about what you can expect to come back from that function call.

2. Documentation and Examples in Code#

Short description:

Types are part of your documentation. API documentation and examples should be in your code. Users get up-to-date information when using your library. No need for a separate website. You can add links, examples, default values, and version information. Mature standards like jsdoc provide a great way to see documentation in your IDE. You can even host it using tools like jsdocs.io or unpiped.

The possible options you can pass to it. That kind of thing. It's all about truth for me. And the first implication is documentation. That's about truth as well, isn't it? So types are part of your documentation or maybe even your documentation. Certainly, types and TS doc, JS doc, I'll use the terms interchangeably even though they're not exactly. But they can provide your library documentation.

So if you think of adding comments immediately before every function, every interface, every constant that you expose from your library, you can actually accurately describe that there. My hot take for today is all of your API documentation and examples should be in your code. It means that when your users are actually using your library, they get up to date, accurate information about the version that they are consuming at that moment in time. You don't have to have a fancy website with a drop down allowing users to select major versions, if your documentation is actually in the code itself. Their editor will surface the correct version for them. You can add links. You can add examples. You have the full power of markdown at your disposal. You can add default values. You can add the version something was introduced to the project at. Anything else that you might think or consider, jsdoc, they're really mature standards. And there's nothing quite that beats being able to see the documentation for what you're using in your IDE rather than having to go somewhere else or perform a quick search. You can even host it that way. Check out jsdocs.io. You can actually type any package in, and they'll render up documentation for you based on the declaration files for that project. You might even consider something like unpiped which is a package in the onjs.github organization which enables you to have a typed configuration schema. It might not be relevant for your project, we use it in Nuxt. We are able to type our configuration schema, and then that can be exported to json or to code. We can do things with it, such as generate documentation programmatically. That is what we use to ensure our Nuxt config documentation is accurate and updated on the website. It is always based on the actual code and the JSTOC in that code file.

Here is just a little example picked from a library I maintain. It is not complex, it is not difficult as an author to do this.

3. Using TypeScript for Documentation and Testing#

Short description:

TypeScript allows you to add only the required values, providing a true-to-life representation of functionality. Testing your types alongside unit tests ensures accurate typing. Tools like Unbuild help with testing built files, ensuring accuracy in development. Versioning types is essential, as changes can break user code or compilation.

You don't need to type everything, TypeScript has got your back as far as that's concerned. You can add only the value that is required. An example of how something might be used, a further explanation of what a particular parameter might be, then obviously some kind of overall statement, and just look at how that comes up. Isn't it beautiful? Doesn't it just surface something that might be really useful as a user of that code?

So there we go, types as documentation. But I think another point from this concept of truth is that we're not just exposing our runtime code, we're also exposing our types as a library. That is our code as well, which means implication number one is we have to test them. I particularly like expect type as a library, and that's what you're seeing here, but test as well is a great tool that I've used also in other projects. So you can actually just test your types alongside your normal unit tests with something like expect type. So you can narrow down on a particular return value and actually expect that that value is going to be the type that you want it to be. In order to make this work, you just need to run ESC and noemmit on your test files as well as running them with your test runner, vtest or just or whatever it is. And don't forget the fact that TypeScript itself is actually able to help us too. Particularly useful is tsexpect error which will throw an error if there is not an error in the following line. It's a great example of saying this should this to generate the red squiggly line when my users do something like this because it shouldn't be allowed. So between expect typeof, which comes with a huge array of helper functions that can be chained off of it and tsexpect error, you can pretty accurately type your code, type interface for your users. I think that's absolutely essential for a library author. I would also recommend as a follow up for that testing your built files because sometimes you can have a situation where the source files are fine from a typing point of view. It's not until things are built that you get some kind of problem. And helping with that are tools like Unbuild and others that enable you to have a stub mode so your dist files in development just effectively point back to your source files. Unbuild writes stubs that work in node so you can actually use it in development. But it also just means that you get the accurate built files when you do actually build your project. As long as in your tests you are importing from your built library. So just type your full project name and then make sure you have tsconfig entry or you've set up an alias in your test runner and that way you can always be testing your built files in your type tests.

Another implication if types are code, version them. Adhere to semver if you can. For example, you might release an enhancement in your project. Normally an enhancement wouldn't trigger that's not a breaking change. But if it changes your type such that something breaks for your users or whether compilation will break in that project, then it is a breaking change. An example would be, I have to put my hand up here, I put a PRN to definitely types to change the type of end and a few other stream-related types and it seems that there was a small discrepancy between reality and the node types. Res end returns this, not void, so we wanted to correct that. But just looking at the implications of that change it was huge.

4. Managing Changes and Exposing Types#

Short description:

Making changes to types requires careful consideration and proper versioning. Tools like API extractor can help maintain type contracts. Deprecating types and adding function overloads can minimize the impact on library maintainers. Exposing only intended types is crucial. Using build tools like rollup-plugin-dts or dts-bundle-generator can control access to types. Types serve as documentation, code, and truth, and should not be used to deceive ourselves or users.

Suddenly streams that were being passed around could not be passed to functions that were expecting the old type of stream. So just making that change was a breaking change for lots and lots of people. It still probably had to be made, but you have to be very careful about it. And it takes a lot of effort to make sure that you version your types properly.

I consider a tool like API extractor. It's incredibly full featured. It is a little bit complex to configure, but it can help with ensuring that your type contracts don't change, that you're able to adhere to when you're releasing new changes to types. And obviously, there are things you can do when you are making changes to ensure that they're not full on breaks, but things are a little bit gentler. So, you can, for example, just deprecate a type if you're renaming it. So, users do have some time to change their usage. And you can do something similar, of with functions, rather than just change the type of the function. Again, this might not be necessary. But in some cases, it could be. You can add an overload, so that the function continues to have the previous signature, but it also has a new signature, and it handles both. So, there are some things you can do, I think, to reduce the impact on you as a library maintainer from having to release new minor or major versions when you're changing your types.

It's also worth saying that if your types are your code, if you're thinking of them as your API and a contract with your users, that it's really important that you're only exposing the types you intend to. There'll be lots of internal types, types that you're using for utility purposes. There might be utility code that is just internal. By default, TypeScript does something which I do find unaccountable, and that is it obviously renders the full structure of your project out in declaration files. So, users can, by adding the path to your source files, access the types and the declarations for every single function and type that is exported in any one of your source files, even if it's not exported from your final entry point and bundle. So, using something like rollup-plugin-dts or dts-bundle-generator means you can actually roll that up so it won't be accessible from your final index.dts. That's a hugely useful thing in conjunction with everything else I've been talking about in terms of testing and versioning your types. There are plenty of build tools that will do this for you already, including unbuild, which I mentioned earlier.

And finally, it's not just types as documentation or types as code, but coming to the real point of it, types as truth. Forgive the philosophical or epistemological point. I think this is what types are all about. They're about exposing the reality of the project, of your library, of how it works and what it does. And the corollary, is that we have to avoid the opportunity for lying to ourselves and our users. Because we do this all the time, and I am very prone to this, it's really easy to put an as or to type something as any. It's very possible to turn off strict null checks and just enjoy the fact that you're not having to...

5. Strictness and Deep Integration of Types#

Short description:

Library authors should be strict and ensure reliable types for users. TypeScript's inference can be used to determine return types, but testing is necessary to ensure accuracy. Moving beyond superficial types to those that deeply integrate with the library improves usability. For example, using string literals instead of generic strings allows for more specific values. An example from the OhMyFetch library demonstrates how response types can be configured based on user preferences.

You're just assuming that it will be set. But I think the discipline for library authors is we have to be as strict as possible, so that what we are generating and declaring to our users is reliable as far as they're concerned. They shouldn't have to test it for us. We should have fully tested it so that our types are accurate.

As much as possible, I like the paradigm called the fountain of truth, where you effectively have the source of truth coming from where something is... from the actual code that processes that is run in a function. Rather than having a function and manually declaring the return type. I know people have different points of view. I much prefer to allow TypeScript to infer that return type. But then to test it, as I've been saying. To ensure what we are getting doesn't change unexpectedly, doesn't become any, doesn't have an unexpected void appearing. But rather than typing it manually, or even worse, using as to talk about the return type, we just ensure that what TypeScript is inferring is what we're intending to be parsing out. That means we don't unexpectedly narrow a type, for example. Or we don't unexpectedly typecast something when we weren't entirely intending to do that.

And then, I think, probably the most significant paradigm shift as a library author is to move from what you might call a superficial use of types to types that actually get under the skin of your library. So, not just, say, describing something. You might have a parameter that's a string. Describing it as a string might not actually be that helpful. It might be accurate, but not that helpful. Moving from a string to a string literal is already worlds better because you're saying these specific values can be passed into my library. That enables you to actually do something that's much more useful for your end user.

So, take this bit of code as an example. So, this is taken and very slightly simplified from a library called OhMyFetch. It's a convenient layer over the fetch API. One of the things that it allows you to do is pass as an option what kind of response you'd like to receive. Do you want to get a JSON response? Well, that's the default. But you might want access to an array buffer of it or a blob or just the string that's coming back. And we want to be able to configure that. But obviously, that's going to change the type of the response. If you're saying you want an array buffer, the type you get back should be an array buffer.

6. Implementing Customization with a Map#

Short description:

Using a map in TypeScript instead of a chain of extends allows for simpler implementation and customization. The mapped type magic enables the return of the actual type based on the string passed in. This approach provides a nice default set of fully typed responses, ensuring accurate matching of the expected return types.

It shouldn't be anything else. It shouldn't allow you to override that type with some custom type. And we've just implemented this quite simply with a map, which is often a nice pattern in TypeScript. Rather than a chain of extends, you can actually just have a map and write a single extends and pass back what you want.

Extends, by the way, is one of the most powerful tools for this kind of customization that we're talking about here. And this particular code, at first, defines those utilities for us. So, here's the map between the string blob text array buffer and the actual type that's going to come back. Then we have, we allow JSON, which is a bit of a wild card in this particular case, because it can really be anything. We want the user to be able to provide an override that will match with actually coming back. And then we have this mapped type magic, which allows us to return back if the user passes in, I guess we are the consumers of it. We pass in text or array buffer, it's going to return back the actual type that matches that string. And so, then we're able to put everything together in the interface for fetch there, which is that whatever those options are, if response type is text, we get a string promise back. If it's an array buffer, we get an array buffer promise back. And if it's JSON, then we either return unknown or we allow the user to override that. And so, we get a nice default set of responses that are fully typed. That's the kind of thing I mean about getting under the skin of the library. And I'm sure that could be improved so much. Put a PRN if you like. But that kind of move of saying, I don't just want to return the type array buffer or blob or string or unknown. I actually want to make sure that what I'm returning is very accurately, as much as I possibly can, matching the actual thing that will come back given that set of inputs to that function.

7. Tips for Achieving Response Specificity#

Short description:

To return a response specific to the user's input, type inference and a no-op helper can be used. By extending the options interface, more complex functionality can be achieved. Normalizing user input and making it accessible for type purposes is crucial.

So, some tips, I think, for achieving that. So, one, it's a really common pattern now, and I think it's needed. In order to access all the information that you might need to return a response that is that specific to what the user is giving you, it's often necessary to use type inference, which is really usable through functions. So, a no-op function that says, well, the user's passing something, and I don't know exactly what it is, but it should match the options paradigm. But by not just saying it is this options interface, but that it extends it, we can then do a lot cooler things with it down the line. Such as say, if this option is this value, we're going to return this. Or if that option is this value, then this other option needs to match it in this kind of way. So, you may need to make use of that kind of no-op helper and have a defined config or defined options or defined interface, defined schema. Whatever it is that you're producing, having this kind of intermediate step where the user sort of provides some kind of input and you normalize it, but make it accessible for yourself for type purposes, is often really, really crucial. Really key.

8. Leveraging Types for Library Benefits#

Short description:

Types can do all the work for you, guiding users to type only what matches the source object. By moving work from runtime to typing, you can generate code based on user access. In Nuxt, components and plugins are typed to match user reality. Automatic type detection allows for injected values in templates. TypeScript typing can reveal specific function return values. Typed API routes enable event handler definition in the server side.

In some cases, it's worth flagging this. Types can actually do all your work for you. This can actually be where your actual library's benefit comes from. So, for example, you have an object passed in. TypeScript is able to you're able to write types that convey the behavior you want. And then you can have something like a proxy do the actual work.

So, maybe your mapping values from the object to something else and using a nested dot notation. You can actually enable the type to be the guide for the user. So, they can only type the kinds of things that match the source object. And then in your code, you have a proxy that just looks at what values the user actually accesses. What properties of the object that they access. And then you're actually able to generate the code and do what they intend to do that way. That's quite fun, I think, when you move the work from the runtime into the typing there.

Here's an example of what we've done in Nuxt. So, in Nuxt, we've tried as much as possible for the typing to match the reality for the user. So, we have the concept of components that are accessible anywhere throughout the app. So, my component should be accessible here. And indeed, it is. We have the type here generated automatically, so the user can actually jump straight to it with the Vue plugin that we recommend. Plugins themselves can inject values into the Nuxt app instance itself and the Vue instance so they can be accessed in the template. And again, we support automatic type detection for that. So, the user can say, I'm injecting Fu, and in the template, we have it available for the user as a property that's been injected.

TypeScript is a little cleverer when you're typing a function. You can actually see the specific value that's coming back at the end, it should. It should be world. Which is, I think, pretty cool. We have typed API routes as well. When you're actually defining an event handler in the server side of your app. This is just a pretty simple example with a string. But you can have something that's much more complex.

9. TypeScript and Nuxt Integration#

Short description:

We know the return value when fetching an endpoint. Composables are auto imported throughout the app, providing help and support for the user. Nuxt writes type declarations in the background and exposes them to the editor for as-you-type support. Feel free to reach out for more information on Nuxt integration and TypeScript tools.

And actually, we are then able to say, well, we actually know what the return value is going to be. So, when you fetch that endpoint, we know that its response is going to be that simple string. Lots of other examples.

Composables might be a useful one. We have a concept of auto imported composables everywhere throughout your application. So, again, we make that type available globally throughout the app. So, if the user actually just types use me anywhere, they're actually going to get the response of the actual composable. So, again, as much as possible, what we're trying to do is give the user help and support for the actual environment that they are interacting with. In this case, their environment, nuxt, is going to auto import these things and make them available to them anywhere. So, the user shouldn't have to do anything extra for that.

And if you're interested to know how nuxt works, it's basically writing type declarations in the background and exposing them to the editor so that the editor can provide the right kind of as you type support. Which I think is pretty cool. I'd love to answer any questions you might have about that later. Well, if you're interested in any of what I've been talking about, whether it's the nuxt integration, or some of the tools that we have at our disposal in TypeScript to make users have a great experience using our libraries, do feel free to write to me, follow me on Twitter, and particularly if you're interested in nuxt, check out the docs, see some of the things we've done with types. I'd love to talk you through that. Follow us on Twitter or join Discord and feel free to ping me a direct message with any questions you might have.

Daniel Roe
Daniel Roe
25 min
29 Apr, 2022

Comments

Sign in or register to post your comment.

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

Full Stack Documentation
JSNation 2022JSNation 2022
28 min
Full Stack Documentation
Top Content
The Talk discusses the shift to full-stack frameworks and the challenges of full-stack documentation. It highlights the power of interactive tutorials and the importance of user testing in software development. The Talk also introduces learn.svelte.dev, a platform for learning full-stack tools, and discusses the roadmap for SvelteKit and its documentation.
Welcome to Nuxt 3
Vue.js London Live 2021Vue.js London Live 2021
29 min
Welcome to Nuxt 3
Top Content
Nux3 has made significant improvements in performance, output optimization, and serverless support. Nuxt Bridge brings the Nitro engine for enhanced performance and easier transition between Nuxt 2 and Nuxt Read. Nuxt 3 supports Webpack 5, Bytes, and Vue 3. NextLab has developed brand new websites using Docus technology. Nuxt.js is recommended for building apps faster and simpler, and Nuxt 2 should be used before migrating to Nuxt 3 for stability. DOCUS is a new project that combines Nuxt with additional features like content modules and an admin panel.
React's Most Useful Types
React Day Berlin 2023React Day Berlin 2023
21 min
React's Most Useful Types
Top Content
Watch video: React's Most Useful Types
Today's Talk focuses on React's best types and JSX. It covers the types of JSX and React components, including React.fc and React.reactnode. The discussion also explores JSX intrinsic elements and react.component props, highlighting their differences and use cases. The Talk concludes with insights on using React.componentType and passing components, as well as utilizing the react.element ref type for external libraries like React-Select.
TypeScript and React: Secrets of a Happy Marriage
React Advanced 2022React Advanced 2022
21 min
TypeScript and React: Secrets of a Happy Marriage
Top Content
React and TypeScript have a strong relationship, with TypeScript offering benefits like better type checking and contract enforcement. Failing early and failing hard is important in software development to catch errors and debug effectively. TypeScript provides early detection of errors and ensures data accuracy in components and hooks. It offers superior type safety but can become complex as the codebase grows. Using union types in props can resolve errors and address dependencies. Dynamic communication and type contracts can be achieved through generics. Understanding React's built-in types and hooks like useState and useRef is crucial for leveraging their functionality.
Remix Flat Routes – An Evolution in Routing
Remix Conf Europe 2022Remix Conf Europe 2022
16 min
Remix Flat Routes – An Evolution in Routing
Top Content
Remix Flat Routes is a new convention that aims to make it easier to see and organize the routes in your app. It allows for the co-location of support files with routes, decreases refactor and redesign friction, and helps apps migrate to Remix. Flat Folders convention supports co-location and allows importing assets as relative imports. To migrate existing apps to Flat Routes, use the Remix Flat Routes package's migration tool.
Making Magic: Building a TypeScript-First Framework
TypeScript Congress 2023TypeScript Congress 2023
31 min
Making Magic: Building a TypeScript-First Framework
Top Content
Daniel Rowe discusses building a TypeScript-first framework at TypeScript Congress and shares his involvement in various projects. Nuxt is a progressive framework built on Vue.js, aiming to reduce friction and distraction for developers. It leverages TypeScript for inference and aims to be the source of truth for projects. Nuxt provides type safety and extensibility through integration with TypeScript. Migrating to TypeScript offers long-term maintenance benefits and can uncover hidden bugs. Nuxt focuses on improving existing tools and finds inspiration in frameworks like TRPC.

Workshops on related topic

React, TypeScript, and TDD
React Advanced 2021React Advanced 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.
Mastering advanced concepts in TypeScript
React Summit US 2023React Summit US 2023
132 min
Mastering advanced concepts in TypeScript
Top Content
Featured WorkshopFree
Jiri Lojda
Jiri Lojda
TypeScript is not just types and interfaces. Join this workshop to master more advanced features of TypeScript that will make your code bullet-proof. We will cover conditional types and infer notation, template strings and how to map over union types and object/array properties. Each topic will be demonstrated on a sample application that was written with basic types or no types at all and we will together improve the code so you get more familiar with each feature and can bring this new knowledge directly into your projects.
You will learn:- - What are conditional types and infer notation- What are template strings- How to map over union types and object/array properties.
Deep TypeScript Tips & Tricks
Node Congress 2024Node Congress 2024
83 min
Deep TypeScript Tips & Tricks
Top Content
Featured 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.
Best Practices and Advanced TypeScript Tips for React Developers
React Advanced 2022React Advanced 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 Your Own Custom Type System
React Summit 2024React Summit 2024
38 min
Building Your Own Custom Type System
Featured Workshop
Kunal Dubey
Kunal Dubey
I'll introduce the audience to a concept where they can have end-to-end type systems that helps ensure typesafety across the teams Such a system not only improves communication between teams but also helps teams collaborate effectively and ship way faster than they used to before. By having a custom type system, teams can also identify the errors and modify the API contracts on their IDE, which contributes to a better Developer Experience. The workshop would primarily leverage TS to showcase the concept and use tools like OpenAPI to generate the typesystem on the client side. 
Integrating LangChain with JavaScript for Web Developers
React Summit 2024React Summit 2024
92 min
Integrating LangChain with JavaScript for Web Developers
Featured Workshop
Vivek Nayyar
Vivek Nayyar
Dive into the world of AI with our interactive workshop designed specifically for web developers. "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" offers a unique opportunity to bridge the gap between AI and web development. Despite the prominence of Python in AI development, the vast potential of JavaScript remains largely untapped. This workshop aims to change that.Throughout this hands-on session, participants will learn how to leverage LangChain—a tool designed to make large language models more accessible and useful—to build dynamic AI agents directly within JavaScript environments. This approach opens up new possibilities for enhancing web applications with intelligent features, from automated customer support to content generation and beyond.We'll start with the basics of LangChain and AI models, ensuring a solid foundation even for those new to AI. From there, we'll dive into practical exercises that demonstrate how to integrate these technologies into real-world JavaScript projects. Participants will work through examples, facing and overcoming the challenges of making AI work seamlessly on the web.This workshop is more than just a learning experience; it's a chance to be at the forefront of an emerging field. By the end, attendees will not only have gained valuable skills but also created AI-enhanced features they can take back to their projects or workplaces.Whether you're a seasoned web developer curious about AI or looking to expand your skillset into new and exciting areas, "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" is your gateway to the future of web development. Join us to unlock the potential of AI in your web projects, making them smarter, more interactive, and more engaging for users.