上一页 1 ··· 91 92 93 94 95 96 97 98 99 ··· 496 下一页
摘要: 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 阅读(56) 评论(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 阅读(61) 评论(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 阅读(95) 评论(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 阅读(49) 评论(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 阅读(48) 评论(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 阅读(50) 评论(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 阅读(20) 评论(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 阅读(47) 评论(0) 推荐(0)
摘要: Similar to Array.findIndex: type FindIndex<T extends readonly any[], K, ACC extends unknown[] = []> = T extends readonly [infer F, ...infer RT] ? K ex 阅读全文
posted @ 2022-11-16 22:34 Zhentiw 阅读(49) 评论(0) 推荐(0)
摘要: type OnPropChangedMethods<T> = { [Key in keyof T & string as `${Key}Changed`]: (cb: (newValue: T[Key]) => void) => void } declare function makeWatched 阅读全文
posted @ 2022-11-16 15:02 Zhentiw 阅读(19) 评论(0) 推荐(0)
上一页 1 ··· 91 92 93 94 95 96 97 98 99 ··· 496 下一页