随笔分类 - TypeScript
摘要:Traversing items of custom data structures, like trees or linked lists, require knowledge of how that data structure is built. That can lead to proble
阅读全文
摘要:Unlike JavaScript's const variable declarations, TypeScript allows you to create fully immutable types. In this lesson, we learn how to create immutab
阅读全文
摘要:There might be cases where you have selective data for your entities. Let's say that you are building a public API endpoint to get all the registered
阅读全文
摘要:In this post, let's see how to make all the optional fields to be required with the help of Required. type User = { name: string; age?: number; gender
阅读全文
摘要:There might be cases where you would want to create a type while excluding some of the properties from a type. Let's say you have a database query on
阅读全文
摘要:For example, we have a interface: We are using it with NestJS backend, in order to validate the request with meanful runtime error message, we can use
阅读全文
摘要:In general, it is not recommeded to use Namespace in Typescript, we should use ES6 module export import syntax. But there are still some good usecases
阅读全文
摘要:TypeScript 2.8 adds the ability for a mapped type to either add or remove a particular modifier. Specifically, a readonly or ? property modifier in a
阅读全文
摘要:The postshows you how to use the null coalescing operator (??) instead of logical or (||) to set default values in TypeScript 3.7 to prevent expected
阅读全文
摘要:TypeScript 3.7 adds support for optional chaining. This lesson shows you how to use it in your code to handle properties that can be null or undefined
阅读全文
摘要:Take away from NGCONF talk. It is a good show case to how to use decorator. One take away is that we can use 'symbol' to uqine key.
阅读全文
摘要:Here we refactor a React TypeScript class component to a function component with a useState hook and discuss how props and state types can be modeled
阅读全文
摘要:Because @types/react has to expose all its internal types, there can be a lot of confusion over how to type specific patterns, particularly around hig
阅读全文
摘要:For example you are building your own module, the same as Lodash: my-lodash.d.ts Normally you can install @types for popluar 3rd-party libs, if you ha
阅读全文
摘要:The DOM can be a bit tricky when it comes to typing. You never really know exactly what you're going to get, so you have to educate your codebase into
阅读全文
摘要:TypeScript can help you with your plain JavaScript files if you add a simple //@ts-check comment. Then you can enhance the experience by add proper JS
阅读全文
摘要:TO get started with TypeScirpt quickly in your local computer is using parcel-bunlder: Create a index.html: Create a index.ts, put whatever you want.
阅读全文
摘要:Decorators are a powerful feature of TypeScript that allow for efficient and readable abstractions when used correctly. In this lesson we will look at
阅读全文
摘要:We will look at how we can use mapped types, conditional types, self-referencing types and the “infer” keyword to create a reusable generic type that
阅读全文
摘要:When working with conditionals types, within the “extends” expression, we can use the “infer” keyword to either get the type of the elements of an arr
阅读全文