摘要:
const obj = { name: "John", age: 33, cars: [ { make: "Ford", age: 10 }, { make: "Tesla", age: 2 }, ], } as const; export type PathKeys<T> = T extends 阅读全文
摘要:
MethodDecorator @Log(level): Console log message @Pref: Mesure time function Log(level: LoggingLevel): MethodDecorator { return ( target: any, propert 阅读全文
摘要:
Create a type-safe string join utility which can be used like so: const hyphenJoiner = join('-') const result = hyphenJoiner('a', 'b', 'c'); // = 'a-b 阅读全文
摘要:
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 阅读全文
摘要:
Let's say you extends from a base class, you intent to override a method in base class class BaseCmp { showCmp() {} hideCmp() {} helperMethod() {} } c 阅读全文
摘要:
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 { 阅读全文
摘要:
Implement a type LengthOfString<S> that calculates the length of the template string (as in 298 - Length of String): type T0 = LengthOfString<"foo"> / 阅读全文
摘要:
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 阅读全文
摘要:
You can use `extends infer X` to assign the result of an expression to a variable type SomeFunction<U> = SuperHeavyComputation<U> extends infer Result 阅读全文
摘要:
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 阅读全文