import type { Step } from "../step.ts"; /** * If your step class has a `get` method you should implement this so users * benefit from type safety. * * e.g. * ```ts * class MyStep extends Step { * __inferGet?: { * [TKey in keyof MyData]: MySpecialStep; * }; * get(key: TKey): MySpecialStep { * // ... * } * } * ``` */ interface HasInferredGet> { /** * TypeScript hack so we can infer the type of getting each key; this key * won't actually have a value */ __inferGet?: TStepByKey; } /** * Determines the keys that a given step represents * * 1. If it implements HasInferredGet, get the explicit keys * 2. Otherwise, if it has a get method, figure out which attributes it accepts * 3. Otherwise, determine the type the Step encodes and extract the keys of that */ type StepGetKeys = TStep extends HasInferredGet ? keyof UStepByKey : TStep extends { get(attr: infer U): any; } ? U : TStep extends Step ? keyof UData : never; /** * Determines the type of the step returned from `get(step, attr)`. * * 1. If it implements HasInferredGet, get a step representing that specific attribute * 2. Otherwise, if it has a get method, return the ReturnType of that method * 3. Otherwise, determine the type the Step encodes and return a Step representing the relevant key of that */ type GetResult> = TStep extends HasInferredGet ? TAttr extends keyof UStepByKey ? UStepByKey[TAttr] : never : TStep extends { get(attr: any): infer UGetStep; } ? UGetStep : TStep extends Step ? TAttr extends keyof UData ? Step : never : never; /** * Call `$step.get(attr)` if possible, falling back to `access($step, attr)`. */ export declare function get & string>($step: TStep, attr: TAttr): GetResult; export {}; //# sourceMappingURL=get.d.ts.map