Skip to content

Commit 4c4c7f0

Browse files
authored
Merge pull request #358 from ut-code/develop
Merge develop into master
2 parents 0cc3d59 + 896c186 commit 4c4c7f0

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

docs/4-advanced/03-typescript/index.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,7 @@ Vite は、標準で TypeScript のトランスパイラが内蔵されていま
383383

384384
2. `name` のみ
385385

386-
```typescript
387-
declare const t:
388-
| { name: string; age: number }
389-
| { name: string; subject: string };
390-
```
386+
2 つの型に共通しているのは `name` プロパティだけなので、`T` 型の変数に必ず存在しているプロパティは`name` のみとなります。よって、`name` のみ使用可能となります。
391387

392388
3. `(v: unknown) => string``(v: string) => never`
393389

@@ -411,10 +407,12 @@ Vite は、標準で TypeScript のトランスパイラが内蔵されていま
411407

412408
もしこのコードが通る場合、実際に渡された `{name: "Tanaka", math: 100}` には存在しないはずの `science` プロパティにアクセスできてしまうことになります。このようなことを防ぐために、引数の型が小さい集合になればなるほど、関数の型は大きな集合になる必要があります。
413409

414-
4. ```typescript
415-
function apply<T, U>(f: (x: T) => U, x: T): U {
416-
return f(x);
417-
}
410+
4. 以下のコード
411+
412+
```typescript
413+
function apply<T, U>(f: (x: T) => U, x: T): U {
414+
return f(x);
415+
}
418416
```
419417

420418
<ViewSource url={import.meta.url} path="_samples/apply" noCodeSandbox />

0 commit comments

Comments
 (0)