Skip to content

Commit

Permalink
Minor tweak to typescript state mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlplusb committed Oct 1, 2019
1 parent 65a2fd8 commit c4efa4f
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,18 @@ type StateMapper<StateModel extends object, Depth extends string> = {
: StateModel[P];
};

type IntermediateStateMapper<Model extends object, Depth extends string> = {
[K in keyof Model]: K extends IndexSignatureKeysOfType<Model>
? Model[K]
: StateMapper<{ 0: Model[K] }, Depth>[0];
};

type RecursiveState<
Model extends object,
Depth extends string
> = Depth extends '6'
? Model
: {
[K in keyof O.Filter<Model, ActionTypes>]: K extends IndexSignatureKeysOfType<Model>
? Model[K]
: StateMapper<{ 0: Model[K] }, Depth>[0]
}
// : O.Merge<
// StateMapper<
// O.Omit<O.Filter<Model, ActionTypes>, IndexSignatureKeysOfType<Model>>,
// Depth
// >,
// O.Pick<Model, IndexSignatureKeysOfType<Model>>
// >;
: IntermediateStateMapper<O.Filter<Model, ActionTypes>, Depth>;

/**
* Filters a model into a type that represents the state only (i.e. no actions)
Expand Down

0 comments on commit c4efa4f

Please sign in to comment.