@ts-ignore cast variance
| 49 | |
| 50 | /** @ts-ignore cast variance */ |
| 51 | interface Type<out t extends object = object, in out $ = {}> |
| 52 | extends BaseType<t, $> { |
| 53 | readonly(): t extends array ? ArrayType<{ readonly [i in keyof t]: t[i] }, $> |
| 54 | : Type<readonlyObjectOf<t>, $> |
| 55 | |
| 56 | // a builtin whose keys aren't props, as an overload only one matches: a |
| 57 | // conditional return, here or on the one below, would be deferred for a |
| 58 | // receiver known only by its constraint, leaving the Type of its keys |
| 59 | // unusable, where a `this` that can't be decided falls through instead. |
| 60 | // that t is a builtin is tested within `this` too: as self's constraint, it |
| 61 | // costs a receiver that isn't one about 4000 instantiations on each call |
| 62 | keyof<self extends { t: object }>( |
| 63 | this: [self["t"]] extends [array | BuiltinObject] ? |
| 64 | isKeylessBuiltin<unbrandKeyofOperand<self["t"]>> extends true ? |
| 65 | self |
| 66 | : never |
| 67 | : never |
| 68 | ): ErrorType<writeUnsatisfiableExpressionError<"keyof">> |
| 69 | // t is read from the receiver: Type<object>'s keys are never, so returning |
| 70 | // arkKeyOf<t> would keep an array or Date Type, which TS relates to |
| 71 | // Type<object> structurally rather than by variance, from being assignable |
| 72 | keyof<o extends object>(this: { |
| 73 | t: o |
| 74 | }): instantiateType<arkKeyOf<unbrandKeyofOperand<o>>, $> |
| 75 | // a union of Types has a t per member, and inference would pick one of them |
| 76 | // for o, which the other members then fail. Indexing gives their union |
| 77 | keyof<self extends { t: object }>( |
| 78 | this: self |
| 79 | ): instantiateType<arkKeyOf<unbrandKeyofOperand<self["t"]>>, $> |
| 80 | |
| 81 | /** |
| 82 | * #### the Type at a key, or at a path of up to three keys |
| 83 | * |
| 84 | * @example |
| 85 | * const User = type({ name: "string", address: { city: "string" } }) |
| 86 | * // Type<string> |
| 87 | * const City = User.get("address", "city") |
| 88 | */ |
| 89 | get<const k1 extends arkIndexableOf<t>, r = instantiateType<gotAt<t, k1>, $>>( |
| 90 | k1: k1 | type.cast<k1> |
| 91 | ): r extends infer _ ? _ : never |
| 92 | get< |
| 93 | const k1 extends arkIndexableOf<t>, |
| 94 | const k2 extends arkIndexableOf<definedAt<t, k1>>, |
| 95 | r = instantiateType<gotAt<definedAt<t, k1>, k2> | undefinedAt<t, k1>, $> |
| 96 | >( |
| 97 | k1: k1 | type.cast<k1>, |
| 98 | k2: k2 | type.cast<k2> |
| 99 | ): r extends infer _ ? _ : never |
| 100 | get< |
| 101 | const k1 extends arkIndexableOf<t>, |
| 102 | const k2 extends arkIndexableOf<definedAt<t, k1>>, |
| 103 | const k3 extends arkIndexableOf<definedAt<definedAt<t, k1>, k2>>, |
| 104 | r = instantiateType< |
| 105 | | gotAt<definedAt<definedAt<t, k1>, k2>, k3> |
| 106 | | undefinedAt<definedAt<t, k1>, k2> |
| 107 | | undefinedAt<t, k1>, |
| 108 | $ |
no outgoing calls
no test coverage detected