Last active
November 16, 2024 13:38
-
-
Save TirolJPN/3044dfd83dbb6d06e75f46cff74fc269 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 13 - Hello World | |
| ------- | |
| by Anthony Fu (@antfu) #お試し | |
| ### 質問 | |
| Hello, World! | |
| Type Challenges では、型システム自体を使用してアサーションを実行します。 | |
| この課題では、次のコードを変更してテストに合格する必要があります(型チェックエラーなし)。 | |
| ```ts | |
| // expected to be string | |
| type HelloWorld = any | |
| ``` | |
| ```ts | |
| // you should make this work | |
| type test = Expect<Equal<HelloWorld, string>> | |
| ``` | |
| 「挑戦する」ボタンをクリックしてコーディングを開始してください! Happy Hacking! | |
| > GitHubで確認する:https://tsch.js.org/13/ja | |
| */ | |
| /* _____________ ここにコードを記入 _____________ */ | |
| type HelloWorld = string // expected to be a string | |
| /* | |
| 4 - Pick | |
| ------- | |
| by Anthony Fu (@antfu) #初級 #union #built-in | |
| ### 質問 | |
| 組み込みの型ユーティリティ`Pick<T, K>`を使用せず、`T`から`K`のプロパティを抽出する型を実装します。 | |
| 例えば: | |
| ```ts | |
| interface Todo { | |
| title: string | |
| description: string | |
| completed: boolean | |
| } | |
| type TodoPreview = MyPick<Todo, 'title' | 'completed'> | |
| const todo: TodoPreview = { | |
| title: 'Clean room', | |
| completed: false, | |
| } | |
| ``` | |
| > GitHubで確認する:https://tsch.js.org/4/ja | |
| */ | |
| /* _____________ ここにコードを記入 _____________ */ | |
| type MyPick<T, K extends keyof T> = { | |
| [Key in K]: T[Key] | |
| } | |
| /* | |
| 7 - Readonly | |
| ------- | |
| by Anthony Fu (@antfu) #初級 #built-in #readonly #object-keys | |
| ### 質問 | |
| 組み込みの型ユーティリティ`Readonly<T>`を使用せず、`T` のすべてのプロパティを読み取り専用にする型を実装します。実装された型のプロパティは再割り当てできません。 | |
| 例えば: | |
| ```ts | |
| interface Todo { | |
| title: string | |
| description: string | |
| } | |
| const todo: MyReadonly<Todo> = { | |
| title: "Hey", | |
| description: "foobar" | |
| } | |
| todo.title = "Hello" // Error: cannot reassign a readonly property | |
| todo.description = "barFoo" // Error: cannot reassign a readonly property | |
| ``` | |
| > GitHubで確認する:https://tsch.js.org/7/ja | |
| */ | |
| /* _____________ ここにコードを記入 _____________ */ | |
| type MyReadonly<T> = { | |
| readonly [Key in keyof T]: T[Key] | |
| } | |
| // TODO: 後で GitHub に移す |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment