随笔分类 -  TypeScript

摘要:Conditional types take generics one step further and allow you to test for a specific condition, based on which the final type will be determined. We 阅读全文
posted @ 2019-01-22 21:01 Zhentiw 阅读(378) 评论(0) 推荐(0)
摘要:The "any" type can be very useful, especially when adding types to an existing JavaScript codebase, but it can also lead to lots of runtime errors, as 阅读全文
posted @ 2019-01-21 21:17 Zhentiw 阅读(369) 评论(0) 推荐(0)
摘要:We usually think of types as something that can define a single layer of an object: with an interface we normally specify a list of a few properties a 阅读全文
posted @ 2019-01-21 02:57 Zhentiw 阅读(383) 评论(0) 推荐(0)
摘要:If you're a library author, it's useful to expose your public types as interfaces, to allow your consumers to extend them if needed. For example: To r 阅读全文
posted @ 2019-01-18 19:18 Zhentiw 阅读(199) 评论(0) 推荐(0)
摘要:Using the optional “+” sign together with mapped type modifiers, we can create more explicit and readable type declarations. We can also use the “-” ( 阅读全文
posted @ 2019-01-17 19:46 Zhentiw 阅读(309) 评论(0) 推荐(0)
摘要:Sometimes we might want to make a function more generic by having it accept a union of different types as an argument. Using the JavaScript “in” opera 阅读全文
posted @ 2019-01-15 20:47 Zhentiw 阅读(201) 评论(0) 推荐(0)
摘要:By setting the strictPropertyInitialization flag in the .tsconfig file, TypeScript will start throwing errors unless we initialize all properties of c 阅读全文
posted @ 2019-01-14 19:21 Zhentiw 阅读(459) 评论(0) 推荐(0)
摘要:When looking at large numbers in code (such as 1800000) it’s oftentimes difficult for the human eye to quickly see how big the number actually is. Typ 阅读全文
posted @ 2019-01-14 16:45 Zhentiw 阅读(153) 评论(0) 推荐(0)
摘要:Mapped types are a powerful and unique feature of TypeScript's type system. They allow you to create a new type by transforming all properties of an e 阅读全文
posted @ 2018-09-21 15:44 Zhentiw 阅读(340) 评论(0) 推荐(0)
摘要:The keyof operator produces a union type of all known, public property names of a given type. You can use it together with lookup types (aka indexed a 阅读全文
posted @ 2018-09-20 22:33 Zhentiw 阅读(372) 评论(0) 推荐(0)
摘要:A literal type is a type that represents exactly one value, e.g. one specific string or number. You can combine literal types with union types to mode 阅读全文
posted @ 2018-09-19 18:11 Zhentiw 阅读(204) 评论(0) 推荐(0)
摘要:As of TypeScript 2.4, it is now possible to define string enums, or more precisely, enums with string members. Just like any other numeric enum, strin 阅读全文
posted @ 2018-09-14 17:36 Zhentiw 阅读(314) 评论(0) 推荐(0)
摘要:Some functions may have different return types depending on the types of the arguments with which they’re invoked. Using TypeScript’s function overloa 阅读全文
posted @ 2018-09-14 16:14 Zhentiw 阅读(423) 评论(0) 推荐(0)
摘要:TypeScript 2.0 introduced a new primitive type called never, the type of values that never occur. It helps model the completion behavior of functions 阅读全文
posted @ 2018-09-14 15:39 Zhentiw 阅读(328) 评论(0) 推荐(0)
摘要:ypeScript 2.2 introduced the object, a type that represents any non-primitive type. It can be used to more accurately type methods such as Object.crea 阅读全文
posted @ 2018-09-14 15:25 Zhentiw 阅读(337) 评论(0) 推荐(0)
摘要:One aspect of control flow based type analysis is that the TypeScript compiler narrows the type of a variable within a type guard. This lesson explore 阅读全文
posted @ 2018-09-13 14:50 Zhentiw 阅读(438) 评论(0) 推荐(0)
摘要:Decorators are a feature of TypeScript that are becoming more and more common in many major libraries. This lesson walks you through what decorators a 阅读全文
posted @ 2018-09-06 03:22 Zhentiw 阅读(121) 评论(0) 推荐(0)
摘要:TypeScript outputs JavaScript, but what are you supposed to do with it? This lesson shows how to take the output and use SystemJS as the module loader 阅读全文
posted @ 2018-09-03 01:53 Zhentiw 阅读(300) 评论(0) 推荐(0)
摘要:Using Object Oriented Programming, OOP, style allows us to apply Inversion of Control, IoC, and more patterns. An IoC container helps decoupling depen 阅读全文
posted @ 2018-08-28 01:17 Zhentiw 阅读(1771) 评论(0) 推荐(0)
摘要:Aspect Oriented Programming, AOP, allows to reuse logic across an entire app in a very neat way, decoupling it from the business logic. Kaop-ts bring 阅读全文
posted @ 2018-08-26 04:26 Zhentiw 阅读(670) 评论(0) 推荐(0)