diff --git a/src/IndexBy.ts b/src/IndexBy.ts index 1bbea1b..99265f4 100644 --- a/src/IndexBy.ts +++ b/src/IndexBy.ts @@ -2,29 +2,21 @@ import { MaybeSelector } from "./MaybeSelector"; import { Selector } from "./Selector"; import { GetSignature } from "./Get"; import { StringProperty } from "./util"; +import { Composable } from "./Composable"; +import { Dimensionality, Structure } from "./Discriminants"; -export type IndexBy = +export type IndexByOverloads = B extends { [key: string]: infer C } - ? IndexByOverloads - : never - -export interface IndexByOverloads { - (key: K): MaybeSelector> - (key: K, defaultValue: C): Selector> - (key: K, getDefault: GetSignature>): Selector> -} - -export type IndexByMaybe = - B extends { [key: string]: infer C } - ? IndexByMaybeOverloads + ? { + (key: K) + : Composable.ComposeResult, D, Dimensionality.Maybe, S, Structure.Select> + (key: K, defaultValue: C) + : Composable.ComposeResult, D, Dimensionality.Single, S, Structure.Select> + (key: K, getDefault: GetSignature>) + : Composable.ComposeResult, D, Dimensionality.Single, S, Structure.Select> + } : never -export interface IndexByMaybeOverloads { - (key: K): MaybeSelector> - (key: K, defaultValue: C): MaybeSelector> - (key: K, getDefault: GetSignature>): MaybeSelector> -} - export namespace IndexBy { const nullIfUndefined = (x: T) => x === undefined ? null : x diff --git a/src/MaybeSelector.spec.ts b/src/MaybeSelector.spec.ts index 7b9a01c..e3d16a9 100644 --- a/src/MaybeSelector.spec.ts +++ b/src/MaybeSelector.spec.ts @@ -5,7 +5,6 @@ import { Get } from './Get'; import { MaybeSelector } from './MaybeSelector'; import { Converter } from './Converter'; import { MaybeConverter } from './MaybeConverter'; -import { IndexBy } from './IndexBy'; import { Biselect } from '.'; import { MaybeGet } from './MaybeGet'; diff --git a/src/MaybeSelector.ts b/src/MaybeSelector.ts index 5a0d43d..7d967d2 100644 --- a/src/MaybeSelector.ts +++ b/src/MaybeSelector.ts @@ -7,7 +7,7 @@ import { Selector } from './Selector' import { MaybeConverter } from './MaybeConverter' import { Converter } from './Converter' import { MaybeSelectorPropOverloads, Prop } from './Prop' -import { IndexBy, IndexByMaybe } from './IndexBy' +import { IndexBy, IndexByOverloads } from './IndexBy' import { Choose, ChooseOverloads } from './Choose'; import { Extension } from './Extension'; import { Memoize } from './Memoize'; @@ -36,7 +36,7 @@ export interface MaybeSelector { modify: Modify compose: MaybeSelectorCompose prop: MaybeSelectorPropOverloads - indexBy: IndexByMaybe + indexBy: IndexByOverloads choose: ChooseOverloads ifDefined: IfDefinedOverloads merge: Merge diff --git a/src/Root.ts b/src/Root.ts index 35955f4..0f4e865 100644 --- a/src/Root.ts +++ b/src/Root.ts @@ -1,13 +1,14 @@ -import { IndexBy } from "./IndexBy"; +import { IndexBy, IndexByOverloads } from "./IndexBy"; import { SelectorPropOverloads, Prop } from "./Prop"; import { MaybeConverter } from "./MaybeConverter"; import { Choose } from "./Choose"; import { Extension } from "./Extension"; import { Memoize } from "./Memoize"; import { Debug } from "./Debug"; +import { Dimensionality, Structure } from './Discriminants'; export interface Root { - indexBy: IndexBy + indexBy: IndexByOverloads prop: SelectorPropOverloads choose(typeGuard: (a: A) => a is B): MaybeConverter extend: (newExt: Extension) => Root diff --git a/src/Selector.ts b/src/Selector.ts index 61dcde7..0fd08de 100644 --- a/src/Selector.ts +++ b/src/Selector.ts @@ -6,7 +6,7 @@ import { MaybeConverter } from './MaybeConverter' import { Converter } from './Converter' import { Composable } from './Composable' import { SelectorPropOverloads, Prop } from './Prop' -import { IndexBy } from './IndexBy'; +import { IndexBy, IndexByOverloads } from './IndexBy'; import { Choose, ChooseOverloads } from './Choose'; import { Extension } from './Extension'; import { Memoize } from './Memoize'; @@ -35,7 +35,7 @@ export interface Selector { modify: Modify compose: SelectorCompose prop: SelectorPropOverloads - indexBy: IndexBy + indexBy: IndexByOverloads choose: ChooseOverloads ifDefined: IfDefinedOverloads merge: Merge