You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey! There might be a reason why this is already not in place, but in the improbable case - the nested key type for the implemented dotted notation can be inferred with something along the lines of:
export type Keys<T> = T extends any ? keyof T : never;
export type PickType<T, K extends Keys<T>> = T extends { [k in K]: infer V } ? V : never;
export type Merge<T extends object> = {
[K in Keys<T>]: PickType<T, K>;
};
export type PrefixKeys<P, T> = {
[Key in `${P & string}.${keyof T & string}`]: T[Key extends `${P & string}.${infer R}`
? R & keyof T
: never];
};
export type Flatten<T> = T &
Merge<
{
[Key in keyof T]: T[Key] extends object ? PrefixKeys<Key, T[Key]> : never;
}[keyof T]
>;
there are multiple ways to go about where would the flattening be introduced (I didn't follow the types deep enough to say where the inference would be of least complexity), but lets say for showcasing purposes, that it's done on
type InstanceOf<T extends AnyAbility, S extends SubjectType> = Flatten<
S extends AnyClass<infer R>
? R
: S extends (...args: any[]) => infer O
? O
: S extends string
? Exclude<Normalize<Generics<T>['abilities']>[1], SubjectType> extends TaggedInterface<string>
? Extract<Normalize<Generics<T>['abilities']>[1], TaggedInterface<S>>
: AnyObject
: never
>;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey! There might be a reason why this is already not in place, but in the improbable case - the nested key type for the implemented dotted notation can be inferred with something along the lines of:
And those could be used for
there are multiple ways to go about where would the flattening be introduced (I didn't follow the types deep enough to say where the inference would be of least complexity), but lets say for showcasing purposes, that it's done on
Would result in the following:
Beta Was this translation helpful? Give feedback.
All reactions