以下のソース(SWR)を読んでいた際に、タイトルのようなソースがありました。
https://github.com/vercel/swr/blob/master/src/types.ts#L6
typescript
1export type Fetcher<Data = unknown, SWRKey extends Key = Key> = 2 /** 3 * () => [{ foo: string }, { bar: number }] | null 4 * () => ( [{ foo: string }, { bar: number } ] as const | null ) 5 */ 6 SWRKey extends (() => readonly [...infer Args] | null) 7 ? ((...args: [...Args]) => FetcherResponse<Data>) 8 /** 9 * [{ foo: string }, { bar: number } ] | null 10 * [{ foo: string }, { bar: number } ] as const | null 11 */ 12 : SWRKey extends (readonly [...infer Args]) 13 ? ((...args: [...Args]) => FetcherResponse<Data>) 14 /** 15 * () => string | null 16 * () => Record<any, any> | null 17 */ 18 : SWRKey extends (() => infer Arg | null) 19 ? (...args: [Arg]) => FetcherResponse<Data> 20 /** 21 * string | null | Record<any,any> 22 */ 23 : SWRKey extends null 24 ? never 25 : SWRKey extends (infer Arg) 26 ? (...args: [Arg]) => FetcherResponse<Data> 27 : never
細かい内容は置いておいて、上記ソースの1行目のようにextendsの後に同じものを=で繋いで記述している意味がわかりません。
typescript
1type Bar = string 2type Foo<T extends Bar = Bar>
これはextendsにどのような挙動を期待しているのでしょうか。
ご教示いただけると幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/10/23 11:10