I am using arg
and fp-ts
. I want to have a function that returns type based on one of the inputs key value.
export const getArg = <T extends Spec> (args: Result<T>) => (argName: {[K in keyof T]: T[K]}): O.Option<T[K]> =>
O.fromNullable(args[argName])
But it says that I can't index with K in keyof T
, despite K
being the actual keys. And it won't see K
in Option
. I need some help with types.
Result
export type Result<T extends Spec> = { _: string[] } & {
[K in keyof T]?: T[K] extends Handler
? ReturnType<T[K]>
: T[K] extends [Handler]
? Array<ReturnType<T[K][0]>>
: never;
};