TypeScript类型挑战-刷题
TypeScript类型挑战
vscode刷题
- vscode 插件
热身题
-
// ============= Test Cases ============= import type { Equal, Expect, NotAny } from "./test-utils";type cases = [Expect<NotAny<HelloWorld>>, Expect<Equal<HelloWorld, string>>];// ============= Your Code Here ============= type HelloWorld = string; // expected to be a string
容易题
-
// ============= Test Cases ============= import type { Equal, Expect } from "./test-utils";type cases = [Expect<Equal<Expected1, MyPick<Todo, "title">>>,Expect<Equal<Expected2, MyPick<Todo, "title" | "completed">>>,// @ts-expect-errorMyPick<Todo, "title" | "completed" | "invalid"> ];interface Todo {title: string;description: string;completed: boolean; }interface Expected1 {title: string; }interface Expected2 {title: string;completed: boolean; }// ============= Your Code Here ============= type MyPick<T, K extends keyof T> = { [Key in K]: T[Key] };