-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
以下の入力をして、AAAA~CCCCの型がどうなっているか見てみるといろいろ壊れてることに気づくと思います。
struct User: Codable {
var name: String
}
struct GenericID<T>: RawRepresentable {
var rawValue: String
}
public typealias AAAA = GenericID<[User]>
public typealias BBBB = GenericID<User?>
public typealias CCCC = GenericID<[String: User]>いろいろ試したところ、以下の形が正しそうです
- 最初のConditional Typeでは
[]で要素数1のタプル化を行う。T | nullが分割されるのを防ぐ。 - 各々の派生タグを
[]で囲む。ジェネリックパラメータのタグはTagRecord側でタプル型にまとまることになっていて、ルールがあっていませんでした
type TagOf<Type> = [Type] extends [TagRecord<infer TAG>]
? TAG
: null extends Type
? "Optional" & [TagOf<Exclude<Type, null>>]
: Type extends (infer E)[]
? "Array" & [TagOf<E>]
: Type extends Map<infer K, infer V>
? "Dictionary" & [K, TagOf<V>]
: never;Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels