摘要: 题目 中文 实现Trim<T>,它是一个字符串类型,并返回一个新字符串,其中两端的空白符都已被删除。 例如 type trimed = Trim<' Hello World '> // expected to be 'Hello World' English Implement Trim<T> wh 阅读全文
posted @ 2022-09-04 23:26 Laggage 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 题目 中文 实现 TrimLeft<T> ,它接收确定的字符串类型并返回一个新的字符串,其中新返回的字符串删除了原字符串开头的空白字符串。 例如 type trimed = TrimLeft<' Hello World '> // 应推导出 'Hello World ' English Implem 阅读全文
posted @ 2022-09-04 23:16 Laggage 阅读(73) 评论(0) 推荐(0) 编辑
摘要: 题目 中文 有时,您可能希望根据某个属性在联合类型中查找类型。 在此挑战中,我们想通过在联合类型Cat | Dog中搜索公共type字段来获取相应的类型。换句话说,在以下示例中,我们期望LookUp<Dog | Cat, 'dog'>获得Dog,LookUp<Dog | Cat, 'cat'>获得C 阅读全文
posted @ 2022-09-04 23:02 Laggage 阅读(42) 评论(0) 推荐(0) 编辑
摘要: 题目 中文 键入函数PromiseAll,它接受PromiseLike对象数组,返回值应为Promise<T>,其中T是解析的结果数组。 const promise1 = Promise.resolve(3); const promise2 = 42; const promise3 = new Pr 阅读全文
posted @ 2022-09-04 22:57 Laggage 阅读(240) 评论(0) 推荐(0) 编辑
摘要: 题目 中文 实现一个通用Pop<T>,它接受一个数组T,并返回一个由数组T的前length-1项以相同的顺序组成的数组。 例如 type arr1 = ['a', 'b', 'c', 'd'] type arr2 = [3, 2, 1] type re1 = Pop<arr1> // expecte 阅读全文
posted @ 2022-09-04 22:10 Laggage 阅读(40) 评论(0) 推荐(0) 编辑
摘要: 题目 中文 实现一个通用Last<T>,它接受一个数组T并返回其最后一个元素的类型。 例如 type arr1 = ['a', 'b', 'c'] type arr2 = [3, 2, 1] type tail1 = Last<arr1> // expected to be 'c' type tai 阅读全文
posted @ 2022-09-04 21:56 Laggage 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 题目 中文 在 JavaScript 中我们经常会使用可串联(Chainable/Pipeline)的函数构造一个对象,但在 TypeScript 中,你能合理的给它赋上类型吗? 在这个挑战中,你可以使用任意你喜欢的方式实现这个类型 - Interface, Type 或 Class 都行。你需要提 阅读全文
posted @ 2022-09-04 21:33 Laggage 阅读(102) 评论(0) 推荐(0) 编辑
摘要: 题目 中文 实现泛型TupleToUnion<T>,它返回元组所有值的合集。 例如 type Arr = ['1', '2', '3'] type Test = TupleToUnion<Arr> // expected to be '1' | '2' | '3' English Implement 阅读全文
posted @ 2022-09-04 20:35 Laggage 阅读(60) 评论(0) 推荐(0) 编辑
摘要: 题目 中文 在类型系统里实现 JavaScript 内置的 Array.concat 方法,这个类型接受两个参数,返回的新数组类型应该按照输入参数从左到右的顺序合并为一个新的数组。 例如: type Result = Concat<[1], [2]> // expected to be [1, 2] 阅读全文
posted @ 2022-09-04 20:14 Laggage 阅读(72) 评论(0) 推荐(0) 编辑
摘要: 题目 中文 实现一个 IF 类型,它接收一个条件类型 C ,一个判断为真时的返回类型 T ,以及一个判断为假时的返回类型 F。 C 只能是 true 或者 false, T 和 F 可以是任意类型。 例如: type A = If<true, 'a', 'b'> // expected to be 阅读全文
posted @ 2022-09-04 20:10 Laggage 阅读(52) 评论(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<Ex 阅读全文
posted @ 2022-09-04 20:00 Laggage 阅读(376) 评论(0) 推荐(0) 编辑
摘要: 题目 中文 实现内置的Exclude <T, U>类型,但不能直接使用它本身。 从联合类型T中排除U的类型成员,来构造一个新的类型。 例如: type Result = MyExclude<'a' | 'b' | 'c', 'a'> // 'b' | 'c' English Implement th 阅读全文
posted @ 2022-09-04 19:47 Laggage 阅读(92) 评论(0) 推荐(0) 编辑