Skip to content

Instantly share code, notes, and snippets.

@lgf-136
Last active September 21, 2022 06:41
Show Gist options
  • Save lgf-136/c1d2911af029b8db7ecf9667d3851f33 to your computer and use it in GitHub Desktop.
Save lgf-136/c1d2911af029b8db7ecf9667d3851f33 to your computer and use it in GitHub Desktop.
type-challenges_easy_pick
{"config":{"codeTheme":"OneDarkPro","pageThemeSyncCodeTheme":true,"openAlmightyConsole":false,"autoRun":false,"layout":"default","keepPreviousLogs":true,"codeFontSize":16},"title":"type-challenges_easy_pick","code":{"HTML":{"language":"html","content":""},"CSS":{"language":"css","content":"","resources":[]},"JS":{"language":"typescript","content":"\r\ninterface Todo {\r\n title: string\r\n description: string\r\n completed: boolean\r\n}\r\n\r\ntype MyPick<T, K extends keyof T> = {\r\n [P in K]: T[P]\r\n }\r\n\r\n// type TodoPreview = MyPick<Todo, 'title'>\r\ntype TodoPreview = MyPick<Todo, 'title' | 'completed'>\r\n// type TodoPreview = MyPick<Todo, 'title' | 'description' | 'completed'>\r\n\r\nconst todo: TodoPreview = {\r\n title: 'Clean room',\r\n completed: false,\r\n}\r\nconsole.log(todo)\r\n\r\n\r\n// vscode template code\r\n// ============= Test Cases =============\r\n// import type { Equal, Expect } from './test-utils';\r\n\r\n// type cases = [\r\n// Expect<Equal<Expected1, MyPick<Todo, 'title'>>>,\r\n// Expect<Equal<Expected2, MyPick<Todo, 'title' | 'completed'>>>,\r\n// // @ts-expect-error\r\n// MyPick<Todo, 'title' | 'completed' | 'invalid'>,\r\n// ];\r\n\r\n// interface Todo {\r\n// title: string;\r\n// description: string;\r\n// completed: boolean;\r\n// }\r\n\r\n// interface Expected1 {\r\n// title: string;\r\n// }\r\n\r\n// interface Expected2 {\r\n// title: string;\r\n// completed: boolean;\r\n// }\r\n\r\n// // ============= Your Code Here =============\r\n// // type MyPick<T, K> = any\r\n// type MyPick<T, K extends keyof T> = {\r\n// [P in K]: T[P];\r\n// };","resources":[]},"VUE":{"language":"vue2","content":"","resources":[]}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment