awesome-typescript icon indicating copy to clipboard operation
awesome-typescript copied to clipboard

A collection of awesome TypeScript resources for client-side and server-side development

Results 71 awesome-typescript issues
Sort by recently updated
recently updated
newest added

### 第七题 使用类型别名定义一个 `EmptyObject` 类型,使得该类型只允许空对象赋值: ```typescript type EmptyObject = {} // 测试用例 const shouldPass: EmptyObject = {}; // 可以正常赋值 const shouldFail: EmptyObject = { // 将出现编译错误 prop: "TS" } ```...

### 第五题 定义一个工具类型 `AppendArgument`,为已有的函数类型增加指定类型的参数,新增的参数名是 `x`,将作为新函数类型的第一个参数。具体的使用示例如下所示: ```typescript type Fn = (a: number, b: string) => number type AppendArgument = // 你的实现代码 type FinalFn = AppendArgument // (x: boolean, a: number, b:...

实现一个 `ToPath` 工具类型,用于把属性访问(`.` 或 `[]`)路径转换为元组的形式。具体的使用示例如下所示: ```typescript type ToPath = // 你的实现代码 ToPath //=> ['foo', 'bar', 'baz'] ToPath //=> ['foo', '0', 'bar', 'baz'] ``` > 请在下面评论你的答案。

实现一个 `Split` 工具类型,根据给定的分隔符(Delimiter)对包含分隔符的字符串进行切割。可用于定义 `String.prototype.split` 方法的返回值类型。具体的使用示例如下所示: ```typescript type Item = 'semlinker,lolo,kakuqo'; type Split< S extends string, Delimiter extends string, > = // 你的实现代码 type ElementType = Split; // ["semlinker", "lolo", "kakuqo"]...

实现一个 `Reverse` 工具类型,用于对元组类型中元素的位置颠倒,并返回该数组。元组的第一个元素会变成最后一个,最后一个元素变成第一个。 ```typescript type Reverse< T extends Array, R extends Array = [] > = // 你的实现代码 type R0 = Reverse // [] type R1 = Reverse // [3,...

实现一个 `Mutable` 工具类型,用于移除对象类型上所有属性或部分属性的 `readonly` 修饰符。具体的使用示例如下所示: ```typescript type Foo = { readonly a: number; readonly b: string; readonly c: boolean; }; type Mutable = // 你的实现代码 const mutableFoo: Mutable = {...

实现一个 `Includes` 工具类型,用于判断指定的类型 `E` 是否包含在 `T` 数组类型中。具体的使用示例如下所示: ```typescript type Includes = // 你的实现代码 type I0 = Includes // false type I1 = Includes // true type I2 = Includes //...

### 第九题 定义一个 `JoinStrArray` 工具类型,用于根据指定的 `Separator` 分隔符,对字符串数组类型进行拼接。具体的使用示例如下所示: ```typescript type JoinStrArray = // 你的实现代码 // 测试用例 type Names = ["Sem", "Lolo", "Kaquko"] type NamesComma = JoinStrArray // "Sem,Lolo,Kaquko" type NamesSpace =...

实现 `UnionToArray` 工具类型,用于将联合类型转换成元组类型。具体的使用示例如下所示: ``` type UnionToArray = // 你的实现代码 type A0 = UnionToArray //=> ['aaa' , 'bbb' , 'ccc'] type A1 = UnionToArray //=> [1, 2, 3] type A2 =...

### 第一题 ```typescript type User = { id: number; kind: string; }; function makeCustomer(u: T): T { // Error(TS 编译器版本:v4.4.2) // Type '{ id: number; kind: string; }' is not...