随笔分类 -  TypeScript

上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 30 下一页
摘要:namespace AllGreetings { export namespace Greetings { export function returnGreeting (greeting: string) { console.log(`The message from namespace Gree 阅读全文
posted @ 2022-09-08 14:54 Zhentiw 阅读(64) 评论(0) 推荐(0)
摘要:Chainable options are commonly used in Javascript. But when we switch to TypeScript, can you properly type it? In this challenge, you need to type an 阅读全文
posted @ 2022-09-08 14:34 Zhentiw 阅读(84) 评论(0) 推荐(0)
摘要:Implement a generic TupleToUnion<T> which covers the values of a tuple to its values union. For example type Arr = ['1', '2', '3'] type Test = TupleTo 阅读全文
posted @ 2022-09-08 13:44 Zhentiw 阅读(45) 评论(0) 推荐(0)
摘要:Implement a generic DeepReadonly<T> which make every parameter of an object - and its sub-objects recursively - readonly. You can assume that we are o 阅读全文
posted @ 2022-09-08 02:44 Zhentiw 阅读(66) 评论(0) 推荐(0)
摘要:Implement a generic MyReadonly2<T, K> which takes two type argument T and K. K specify the set of properties of T that should set to Readonly. When K  阅读全文
posted @ 2022-09-08 02:28 Zhentiw 阅读(31) 评论(0) 推荐(0)
摘要:Implement the built-in Omit<T, K> generic without using it. Constructs a type by picking all properties from T and then removing K For example interfa 阅读全文
posted @ 2022-09-06 15:03 Zhentiw 阅读(32) 评论(0) 推荐(0)
摘要:Implement the built-in ReturnType<T> generic without using it. For example const fn = (v: boolean) => { if (v) return 1 else return 2 } type a = MyRet 阅读全文
posted @ 2022-09-06 14:41 Zhentiw 阅读(35) 评论(0) 推荐(0)
摘要:Implement the built-in Parameters generic without using it. For example: const foo = (arg1: string, arg2: number): void => {} type FunctionParamsType 阅读全文
posted @ 2022-09-03 23:44 Zhentiw 阅读(26) 评论(0) 推荐(0)
摘要:Implement the type version of Array.unshift For example: type Result = Unshift<[1, 2], 0> // [0, 1, 2,] /* _____________ Your Code Here _____________ 阅读全文
posted @ 2022-09-03 23:34 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:Implement the generic version of Array.push For example: type Result = Push<[1, 2], '3'> // [1, 2, '3'] /* _____________ Your Code Here _____________ 阅读全文
posted @ 2022-09-03 23:31 Zhentiw 阅读(38) 评论(0) 推荐(0)
摘要:Implement the Equal<T, U> For example: type isEqual = Equal<1, 1> // true Idea: Parameter type: <P>(x: P) => any Check P extends T ? 1: 2 Then check P 阅读全文
posted @ 2022-09-03 23:30 Zhentiw 阅读(30) 评论(0) 推荐(0)
摘要:Implement the JavaScript Array.includes function in the type system. A type takes the two arguments. The output should be a boolean true or false. For 阅读全文
posted @ 2022-09-02 20:19 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:Implement the JavaScript Array.concat function in the type system. A type takes the two arguments. The output should be a new array that includes inpu 阅读全文
posted @ 2022-09-02 19:20 Zhentiw 阅读(38) 评论(0) 推荐(0)
摘要:Implement a utils If which accepts condition C, a truthy return type T, and a falsy return type F. C is expected to be either true or false while T an 阅读全文
posted @ 2022-09-02 19:16 Zhentiw 阅读(25) 评论(0) 推荐(0)
摘要:If we have a type which is wrapped type like Promise. How we can get a type which is inside the wrapped type? For example: if we have Promise<ExampleT 阅读全文
posted @ 2022-09-02 01:44 Zhentiw 阅读(36) 评论(0) 推荐(0)
摘要:Implement the built-in Exclude<T, U> For example: type Result = MyExclude<'a' | 'b' | 'c', 'a'> // 'b' | 'c' /* _____________ Your Code Here _________ 阅读全文
posted @ 2022-09-02 01:39 Zhentiw 阅读(32) 评论(0) 推荐(0)
摘要:For given a tuple, you need create a generic Length, pick the length of the tuple For example: type tesla = ['tesla', 'model 3', 'model X', 'model Y'] 阅读全文
posted @ 2022-09-02 01:37 Zhentiw 阅读(30) 评论(0) 推荐(0)
摘要:Implement a generic First<T> that takes an Array T and returns it's first element's type. type arr1 = ['a', 'b', 'c'] type arr2 = [3, 2, 1] type head1 阅读全文
posted @ 2022-09-02 01:30 Zhentiw 阅读(26) 评论(0) 推荐(0)
摘要:For example: const tuple = ['tesla', 'model 3', 'model X', 'model Y'] as const type result = TupleToObject<typeof tuple> // expected { tesla: 'tesla', 阅读全文
posted @ 2022-08-31 15:51 Zhentiw 阅读(34) 评论(0) 推荐(0)
摘要:For example: interface Todo { title: string description: string } const todo: MyReadonly<Todo> = { title: "Hey", description: "foobar" } todo.title = 阅读全文
posted @ 2022-08-31 15:26 Zhentiw 阅读(31) 评论(0) 推荐(0)

上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 30 下一页