Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor isDuplicated type #4

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,29 @@ type InferState<Configs> = Configs extends [
} & InferState<Rest>
: unknown;

type IsDuplicated<Name, Names extends unknown[]> = Names extends [
infer One,
type InferStateNames<Configs> = Configs extends [
SliceConfig<infer Name, infer Value, infer _Actions>,
...infer Rest,
]
? One extends Name
? true
: IsDuplicated<Name, Rest>
: false;
? { [name in Name]: Value } & InferStateNames<Rest>
: unknown;

type IsDuplicated<PrevConfigs, Config> =
Config extends SliceConfig<infer Name, infer _Value, infer Actions>
? Extract<keyof InferState<PrevConfigs>, Name> extends never
? Extract<keyof InferStateNames<PrevConfigs>, keyof Actions> extends never
? false
: true
: true
: false;

type HasDuplicatedNames<
Configs,
Names extends string[] = [],
> = Configs extends [
SliceConfig<infer Name, infer _Value, infer Actions>,
...infer Rest,
]
? Name extends Names[number]
PrevConfigs extends Array<unknown> = [],
> = Configs extends [infer One, ...infer Rest]
? IsDuplicated<PrevConfigs, One> extends true
? true
: IsDuplicated<keyof Actions, Names> extends true
? true
: HasDuplicatedNames<Rest, [Name, ...Names]>
: HasDuplicatedNames<Rest, [...PrevConfigs, One]>
: false;

type HasDuplicatedArgs<Configs, State> = Configs extends [
Expand Down