File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed
docs/4-advanced/03-typescript Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -383,11 +383,7 @@ Vite は、標準で TypeScript のトランスパイラが内蔵されていま
383383
3843842 . ` 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
3923883 . ` (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 />
You can’t perform that action at this time.
0 commit comments