Want to become a TypeScript pro? Master advanced TypeScript skills with these resources, from type definitions and challenging type puzzles to practical utility libraries and API development tools.
1. DefinitelyTyped — A collection of type definitions
DefinitelyTyped serves as a community-driven collection of high-quality TypeScript type definitions.
!!! Important! This repo has recently changed layout! !!!
Definitely Typed has recently changed to a proper pnpm monorepo; you may want to reread this document for changes to the layout of packages in this repo.
At the very least, you may want to git clean -fdx the repo (or node ./scripts/clean-node-modules.js on Windows) to clean up node_modules and run pnpm install --filter . to install the workspace root. See further sections for more info on pnpm install.
Current status
This section tracks the health of the repository and publishing process.
It may be helpful for contributors experiencing any issues with their PRs and packages.
In simple terms, it provides TypeScript interfaces and type information for JavaScript libraries that don’t have them built-in.
When you’re using a JavaScript library in a TypeScript project, TypeScript needs to know the shapes and types of the library’s exports to type-check your code correctly.
It’s highly popular and has over 100 million weekly downloads!
This repo allows developers to use existing JavaScript libraries within their TypeScript projects seamlessly, ensuring type safety.
If the library doesn’t provide its own types, you can likely find them in DefinitelyTyped. These type definitions are then used by the TypeScript compiler to understand the library’s structure, offering auto-completion, type checking, and other IDE features for a smoother development experience.
Example (Lodash)
Let’s say you’re working on a TypeScript project and decide to use Lodash, a popular utility library. Lodash itself is written in JavaScript and doesn’t include TypeScript definitions.
Here's how you can use Lodash with types in your project with the help of DefinitelyTyped:
First, install Lodash:
npm install lodash
Then, install the type definitions for Lodash from DefinitelyTyped:
npm install @types/lodash --save-dev
Now, you can use Lodash in your TypeScript file with full type support:
import_from'lodash';// Example usage with full type supportletnumArray:number[]=[1,2,3,4,5];letsum:number=_.sum(numArray);// Lodash's sum functionconsole.log(sum);// Output will be 15
By using DefinitelyTyped's type definitions, you can maintain type safety and take full advantage of TypeScript's features, even when using JavaScript libraries.
2. Type Challenges — A collection of TypeScript puzzles
The repo provides a collection of TypeScript puzzles similar to LeetCode problems.
Each challenge focuses on a specific aspect of TypeScript’s type system, from basic concepts to complex type manipulation. You’ll often need to use generic types or apply advanced features like conditional types and mapped types to solve them.
by the power of TypeScript's well-known Turing Completed type system
High-quality types can help improve projects' maintainability while avoiding potential bugs.
There are a bunch of awesome type utility libraries that may boost your works on types, like ts-toolbelt, utility-types, SimplyTyped, etc., which you can already use.
This project is aimed at helping you better understand how the type system works, writing your own utilities, or just having fun with the challenges. We are also trying to form a community where you can ask questions and get answers you have faced in the real world - they may become part of the challenges!
Challenges
Click the following badges to see details of the challenges.
Providing a set of Common Types for TypeScript projects that are idiomatic and complementary to existing TypeScript Mapped Types so you don't need to copy them between the projects.
These types exist solely at compile time, leaving no runtime cost in your final JavaScript code.
Example: TypeScript Typeguard isPrimitive
First, install utility-types:
npm install utility-types
Let's use isPrimitive Typeguard example - a TypeScript Typeguard for the Primitive type
This can be useful to control the type of a parameter as the program flows.
import{Primitive,isPrimitive}from'utility-types';constconsumer=(param:Primitive[]|Primitive):string=>{if (isPrimitive(param)){// typeof param === PrimitivereturnString(param)+' was Primitive';}// typeof param === Primitive[]constresultArray=param.map(consumer).map(rootString=>'\n\t'+rootString);returnresultArray.reduce((comm,newV)=>comm+newV,'this was nested:');};
Primitive: This type represents the basic building blocks of JavaScript and TypeScript values: strings, numbers, booleans, etc. isPrimitive: This type guard function lets you dynamically check if a given variable is a primitive type. This is especially valuable when working with data that could have varying structures.
Benefits of using utility-types:
Cleaner code: The isPrimitive type guard avoids manual typeof checks and potential branching.
Type safety: It ensures that we're only manipulating primitive values within the appropriate code block.
4. Typescript book — Open-source e-book
Free and open-source e-book that dives deeply into TypeScript's features. Perfect if you prefer a traditional book-like format.
You can freely access, read, and even contribute to the book’s content.
Thanks for the wonderful book. Learned a lot from it. (link)
Its probably the Best TypeScript book out there. Good Job (link)
Love how precise and clear the examples and explanations are! (link)
For the low, low price of free, you get pages of pure awesomeness. Chock full of source code examples and clear, concise explanations, TypeScript Deep Dive will help you learn TypeScript development. (link)
Just a big thank you! Best TypeScript 2 detailed explanation! (link)
This gitbook got my project going pronto. Fluent easy read 5 stars…
The book is known for its easy-to-understand explanations and illustrative examples. This makes it suitable for both beginners and experienced programmers who want to improve their TypeScript knowledge.
The book describes various aspects of TypeScript, from its core concepts and syntax to advanced topics like generics, decorators, and metaprogramming.
tRPC offers a solution for building modern APIs with a focus on type safety and developer experience. This open-source project provides tools and libraries needed to construct type-safe APIs.
Thanks for the wonderful book. Learned a lot from it. (link)
Its probably the Best TypeScript book out there. Good Job (link)
Love how precise and clear the examples and explanations are! (link)
For the low, low price of free, you get pages of pure awesomeness. Chock full of source code examples and clear, concise explanations, TypeScript Deep Dive will help you learn TypeScript development. (link)
Just a big thank you! Best TypeScript 2 detailed explanation! (link)
This gitbook got my project going pronto. Fluent easy read 5 stars…
tRPC integrates seamlessly with popular web frameworks such as React, Next.js and Express.js.
Type-safe APIs have several advantages:
Reduced Errors: Static type checking helps catch potential errors at development time, preventing runtime issues that can be difficult to debug later.
Improved Maintainability: A type-safe API provides a clear understanding of the data structures and interactions involved.
Enhanced Developer Experience: Autocompletion and other IDE features powered by static types can significantly improve development speed and overall developer satisfaction.
Becoming a true TypeScript expert takes time and practice. These resources will help you build a strong start. Keep learning, keep trying new things, and connect with other TypeScript developers to take your skills to the next level.