随笔分类 -  TypeScript

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 30 下一页
摘要:Implement type IsPalindrome<T> to check whether a string or number is palindrome. For example: IsPalindrome<'abc'> // false IsPalindrome<121> // true 阅读全文
posted @ 2022-11-29 15:14 Zhentiw 阅读(13) 评论(0) 推荐(0)
摘要:Implement the type version of Object.fromEntries For example: interface Model { name: string; age: number; locations: string[] | null; } type ModelEnt 阅读全文
posted @ 2022-11-28 15:54 Zhentiw 阅读(29) 评论(0) 推荐(0)
摘要:Implement a generic GetReadonlyKeys<T> that returns a union of the readonly keys of an Object. For example interface Todo { readonly title: string rea 阅读全文
posted @ 2022-11-27 19:47 Zhentiw 阅读(131) 评论(0) 推荐(0)
摘要:Implement a generic IsRequiredKey<T, K> that return whether K are required keys of T . For example type A = IsRequiredKey<{ a: number, b?: string },'a 阅读全文
posted @ 2022-11-26 16:27 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要:Implement the generic ClassPublicKeys<T> which returns all public keys of a class. For example: class A { public str: string protected num: number pri 阅读全文
posted @ 2022-11-26 16:14 Zhentiw 阅读(16) 评论(0) 推荐(0)
摘要:The well known split() method splits a string into an array of substrings by looking for a separator, and returns the new array. The goal of this chal 阅读全文
posted @ 2022-11-25 15:15 Zhentiw 阅读(25) 评论(0) 推荐(0)
摘要:Drop the specified chars from a string. For example: type Butterfly = DropString<'foobar!', 'fb'> // 'ooar!' /* _____________ Your Code Here _________ 阅读全文
posted @ 2022-11-25 01:15 Zhentiw 阅读(22) 评论(0) 推荐(0)
摘要:Implement Camelize which converts object from snake_case to to camelCase Camelize<{ some_prop: string, prop: { another_prop: string }, array: [{ snake 阅读全文
posted @ 2022-11-24 15:16 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:import { assign, createMachine } from "xstate"; type FetchStates = | { value: "idle"; context: FetchContext & { results: []; message: ""; }; } | { val 阅读全文
posted @ 2022-11-23 16:39 Zhentiw 阅读(60) 评论(0) 推荐(0)
摘要:Create a type-level function whose types is similar to Pinia library. You don't need to implement function actually, just adding types. Overview This 阅读全文
posted @ 2022-11-22 16:02 Zhentiw 阅读(37) 评论(0) 推荐(0)
摘要:import React, { useState } from "react"; type Base = { id: string } | string; type GenericSelectProps<TValue> = { formatLabel: (value: TValue) => stri 阅读全文
posted @ 2022-11-21 15:48 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:Implement a type DeepPick, that extends Utility types Pick. A type takes two arguments. For example: type obj = { name: 'hoge', age: 20, friend: { nam 阅读全文
posted @ 2022-11-21 15:32 Zhentiw 阅读(51) 评论(0) 推荐(0)
摘要: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 阅读(28) 评论(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 阅读(75) 评论(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 阅读(41) 评论(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 阅读(47) 评论(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 阅读(86) 评论(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 阅读(39) 评论(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 阅读(31) 评论(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 阅读(49) 评论(0) 推荐(0)

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 30 下一页