随笔分类 - 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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:Using the optional “+” sign together with mapped type modifiers, we can create more explicit and readable type declarations. We can also use the “-” (
阅读全文
摘要: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
阅读全文
摘要:By setting the strictPropertyInitialization flag in the .tsconfig file, TypeScript will start throwing errors unless we initialize all properties of c
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:Some functions may have different return types depending on the types of the arguments with which they’re invoked. Using TypeScript’s function overloa
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:Using Object Oriented Programming, OOP, style allows us to apply Inversion of Control, IoC, and more patterns. An IoC container helps decoupling depen
阅读全文
摘要: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
阅读全文

浙公网安备 33010602011771号