随笔分类 -  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 阅读全文
posted @ 2020-09-27 16:21 Zhentiw 阅读(198) 评论(0) 推荐(0)
摘要:Unlike JavaScript's const variable declarations, TypeScript allows you to create fully immutable types. In this lesson, we learn how to create immutab 阅读全文
posted @ 2020-02-26 00:25 Zhentiw 阅读(673) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2020-02-26 00:15 Zhentiw 阅读(152) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2020-02-16 22:53 Zhentiw 阅读(174) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2020-02-16 22:51 Zhentiw 阅读(207) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2020-01-19 17:45 Zhentiw 阅读(269) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2020-01-16 16:58 Zhentiw 阅读(159) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-10-17 19:02 Zhentiw 阅读(157) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-10-10 15:25 Zhentiw 阅读(207) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-10-10 15:22 Zhentiw 阅读(435) 评论(0) 推荐(0)
摘要: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. 阅读全文
posted @ 2019-05-10 20:08 Zhentiw 阅读(467) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-27 21:00 Zhentiw 阅读(420) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-27 20:45 Zhentiw 阅读(1034) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-02-06 03:32 Zhentiw 阅读(313) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-01-29 19:14 Zhentiw 阅读(579) 评论(0) 推荐(1)
摘要: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 阅读全文
posted @ 2019-01-29 19:04 Zhentiw 阅读(399) 评论(0) 推荐(0)
摘要: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. 阅读全文
posted @ 2019-01-28 15:45 Zhentiw 阅读(207) 评论(0) 推荐(0)
摘要:Decorators are a powerful feature of TypeScript that allow for efficient and readable abstractions when used correctly. In this lesson we will look at 阅读全文
posted @ 2019-01-27 22:30 Zhentiw 阅读(448) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-01-25 20:13 Zhentiw 阅读(296) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-01-24 20:15 Zhentiw 阅读(857) 评论(0) 推荐(0)