上一页 1 ··· 62 63 64 65 66 67 68 69 70 ··· 468 下一页
摘要: const obj = { name: "John", age: 33, cars: [ { make: "Ford", age: 10 }, { make: "Tesla", age: 2 }, ], } as const; export type PathKeys<T> = T extends 阅读全文
posted @ 2022-11-21 00:24 Zhentiw 阅读(22) 评论(0) 推荐(0) 编辑
摘要: MethodDecorator @Log(level): Console log message @Pref: Mesure time function Log(level: LoggingLevel): MethodDecorator { return ( target: any, propert 阅读全文
posted @ 2022-11-20 18:01 Zhentiw 阅读(65) 评论(0) 推荐(0) 编辑
摘要: Create a type-safe string join utility which can be used like so: const hyphenJoiner = join('-') const result = hyphenJoiner('a', 'b', 'c'); // = 'a-b 阅读全文
posted @ 2022-11-19 20:13 Zhentiw 阅读(28) 评论(0) 推荐(0) 编辑
摘要: Implement a type, UnionToTuple, that converts a union to a tuple. As we know, union is an unordered structure, but tuple is an ordered, which implies 阅读全文
posted @ 2022-11-19 00:52 Zhentiw 阅读(39) 评论(0) 推荐(0) 编辑
摘要: Let's say you extends from a base class, you intent to override a method in base class class BaseCmp { showCmp() {} hideCmp() {} helperMethod() {} } c 阅读全文
posted @ 2022-11-18 15:31 Zhentiw 阅读(80) 评论(0) 推荐(0) 编辑
摘要: You can give Getter or Setter different types. So that Setter can accpet a wider range of types, while Getter can return a narrow type. class Thing { 阅读全文
posted @ 2022-11-18 15:22 Zhentiw 阅读(31) 评论(0) 推荐(0) 编辑
摘要: Implement a type LengthOfString<S> that calculates the length of the template string (as in 298 - Length of String): type T0 = LengthOfString<"foo"> / 阅读全文
posted @ 2022-11-18 02:37 Zhentiw 阅读(22) 评论(0) 推荐(0) 编辑
摘要: Typescript has NonNullable<T>, let's build a Nullable<T> type Nullable<T extends Record<PropertyKey, unknown>> = { [K in keyof T]: T[K] | null } type 阅读全文
posted @ 2022-11-17 15:16 Zhentiw 阅读(42) 评论(0) 推荐(0) 编辑
摘要: You can use `extends infer X` to assign the result of an expression to a variable type SomeFunction<U> = SuperHeavyComputation<U> extends infer Result 阅读全文
posted @ 2022-11-17 15:11 Zhentiw 阅读(8) 评论(0) 推荐(0) 编辑
摘要: The enum is an original syntax of TypeScript (it does not exist in JavaScript). So it is converted to like the following form as a result of transpila 阅读全文
posted @ 2022-11-16 22:35 Zhentiw 阅读(26) 评论(0) 推荐(0) 编辑
上一页 1 ··· 62 63 64 65 66 67 68 69 70 ··· 468 下一页