随笔分类 - TypeScript
摘要:Implement Python liked any function in the type system. A type takes the Array and returns true if any element of the Array is true. If the Array is e
阅读全文
摘要:Get an Object that is the difference between O & O1 /* _____________ Your Code Here _____________ */ type Diff<T, S> = { [K in Exclude<(keyof T | keyo
阅读全文
摘要:const fruitCounts = { apple: 12, banana: 23 } type PropUnion<T extends Record<PropertyKey, any>> = { [K in keyof T]: { [K2 in K]: T[K2] } }[keyof T] t
阅读全文
摘要:Replace the camelCase or PascalCase string with kebab-case. FooBarBaz -> foo-bar-baz For example type FooBarBaz = KebabCase<"FooBarBaz">; const foobar
阅读全文
摘要:Merge two types into a new type. Keys of the second type overrides keys of the first type. For example type foo = { name: string; age: string; } type
阅读全文
摘要:Implement the String to Union type. Type take string argument. The output should be a union of input letters For example type Test = '123'; type Resul
阅读全文
摘要:Implement the Absolute type. A type that take string, number or bigint. The output should be a positive number string For example type Test = -100; ty
阅读全文
摘要:In this challenge, you would need to write a type that takes an array and emitted the flatten array type. For example: type flatten = Flatten<[1, 2, [
阅读全文
摘要:Implement permutation type that transforms union types into the array that includes permutations of unions. type perm = Permutation<'A' | 'B' | 'C'>;
阅读全文
摘要:Compute the length of a string literal, which behaves like String#length. /* _____________ Your Code Here _____________ */ type LengthOfString<S exten
阅读全文
摘要:For given function type Fn, and any type A (any in this context means we don't restrict the type, and I don't have in mind any type 😉) create a gener
阅读全文
摘要:Implement ReplaceAll<S, From, To> which replace the all the substring From with To in the given string S For example type replaced = ReplaceAll<'t y p
阅读全文
摘要:Implement Replace<S, From, To> which replace the string From with To once in the given string S For example type replaced = Replace<'types are fun!',
阅读全文
摘要:Implement Capitalize<T> which converts the first letter of a string to uppercase and leave the rest as-is. For example type capitalized = Capitalize<'
阅读全文
摘要:Implement Trim<T> which takes an exact string type and returns a new string with the whitespace from both ends removed. For example type trimmed = Tri
阅读全文
摘要:Implement TrimLeft<T> which takes an exact string type and returns a new string with the whitespace beginning removed. For example type trimed = TrimL
阅读全文
摘要:Sometimes, you may want to lookup for a type in a union to by their attributes. In this challenge, we would like to get the corresponding type by sear
阅读全文
摘要:Type the function PromiseAll that accepts an array of PromiseLike objects, the returning value should be Promise<T> where T is the resolved result arr
阅读全文
摘要:TypeScript 4.0 is recommended in this challenge Implement a generic Pop<T> that takes an Array T and returns an Array without it's last element. For e
阅读全文
摘要:TypeScript 4.0 is recommended in this challenge Implement a generic Last<T> that takes an Array T and returns its last element. For example type arr1
阅读全文