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

Fix set/update #23

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions docs/globals.html
Original file line number Diff line number Diff line change
Expand Up @@ -2645,7 +2645,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> fp<wbr>Set</h3>
<div class="tsd-signature tsd-kind-icon">fp<wbr>Set<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">fpSetImplementation</span><span class="tsd-signature-symbol"> =&nbsp;fpSetImplementation</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in fpSet/fpSet.ts:125</li>
<li>Defined in fpSet/fpSet.ts:131</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2872,7 +2872,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> set</h3>
<div class="tsd-signature tsd-kind-icon">set<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">SetFn</span><span class="tsd-signature-symbol"> =&nbsp;setImplementation</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in set/set.ts:120</li>
<li>Defined in set/set.ts:122</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2939,8 +2939,8 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> update</h3>
<div class="tsd-signature tsd-kind-icon">update<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">UpdateFn</span><span class="tsd-signature-symbol"> =&nbsp;updateImplementation</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in fpUpdate/fpUpdate.ts:170</li>
<li>Defined in update/update.ts:168</li>
<li>Defined in fpUpdate/fpUpdate.ts:176</li>
<li>Defined in update/update.ts:180</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
8 changes: 4 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2646,7 +2646,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> fp<wbr>Set</h3>
<div class="tsd-signature tsd-kind-icon">fp<wbr>Set<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">fpSetImplementation</span><span class="tsd-signature-symbol"> =&nbsp;fpSetImplementation</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in fpSet/fpSet.ts:125</li>
<li>Defined in fpSet/fpSet.ts:131</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2873,7 +2873,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> set</h3>
<div class="tsd-signature tsd-kind-icon">set<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">SetFn</span><span class="tsd-signature-symbol"> =&nbsp;setImplementation</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in set/set.ts:120</li>
<li>Defined in set/set.ts:122</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2940,8 +2940,8 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> update</h3>
<div class="tsd-signature tsd-kind-icon">update<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">UpdateFn</span><span class="tsd-signature-symbol"> =&nbsp;updateImplementation</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in fpUpdate/fpUpdate.ts:170</li>
<li>Defined in update/update.ts:168</li>
<li>Defined in fpUpdate/fpUpdate.ts:176</li>
<li>Defined in update/update.ts:180</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
"husky": "^4.0.10",
"jest": "^24.9.0",
"ts-jest": "^24.3.0",
"tslint": "^5.20.1",
"tsd": "^0.11.0",
"tslint-config-prettier": "^1.18.0",
"tslint-config-standard": "^9.0.0",
"tslint": "^5.20.1",
"//": "NOTE: Typedoc mustn't be updated to ^0.16.0 as it has breaking changes",
"typedoc": "^0.15.8",
"typescript": "^3.7.5"
Expand All @@ -45,6 +46,5 @@
"homepage": "https://github.com/Siegrift/tsfunct#readme",
"directories": {
"doc": "docs"
},
"dependencies": {}
}
}
64 changes: 35 additions & 29 deletions src/fpSet/fpSet.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
import { Optional, UnwrapOptional as U } from '../common/types'
import baseSet from '../common/baseSet'

type FpSet1<T, K1 extends keyof T> = T extends any[]
type FpSet1<T, K1 extends keyof T, R> = T extends any[]
? T
: Pick<T, Exclude<keyof T, K1>> &
{ [KK1 in K1]-?: Required<Pick<T, KK1>>[KK1] }
: Pick<T, Exclude<keyof T, K1>> & { [KK1 in K1]: R }

type FpSet2<T, K1 extends keyof T, K2 extends keyof U<T[K1]>> = T extends any[]
type FpSet2<
T,
K1 extends keyof T,
K2 extends keyof U<T[K1]>,
R
> = T extends any[]
? T
: Pick<T, Exclude<keyof T, K1>> &
{ [KK1 in K1]-?: Required<{ [key in K1]: FpSet1<U<T[K1]>, K2> }>[KK1] }
{ [KK1 in K1]-?: { [key in K1]: FpSet1<U<T[K1]>, K2, R> }[KK1] }

type FpSet3<
T,
K1 extends keyof T,
K2 extends keyof U<T[K1]>,
K3 extends keyof U<U<T[K1]>[K2]>
K3 extends keyof U<U<T[K1]>[K2]>,
R
> = T extends any[]
? T
: Pick<T, Exclude<keyof T, K1>> &
{
[KK1 in K1]-?: Required<{ [key in K1]: FpSet2<U<T[K1]>, K2, K3> }>[KK1]
[KK1 in K1]-?: { [key in K1]: FpSet2<U<T[K1]>, K2, K3, R> }[KK1]
}

type FpSet4<
T,
K1 extends keyof T,
K2 extends keyof U<T[K1]>,
K3 extends keyof U<U<T[K1]>[K2]>,
K4 extends keyof U<U<U<T[K1]>[K2]>[K3]>
K4 extends keyof U<U<U<T[K1]>[K2]>[K3]>,
R
> = T extends any[]
? T
: Pick<T, Exclude<keyof T, K1>> &
{
[KK1 in K1]-?: Required<
{ [key in K1]: FpSet3<U<T[K1]>, K2, K3, K4> }
>[KK1]
[KK1 in K1]-?: { [key in K1]: FpSet3<U<T[K1]>, K2, K3, K4, R> }[KK1]
}

type FpSet5<
Expand All @@ -44,58 +48,60 @@ type FpSet5<
K2 extends keyof U<T[K1]>,
K3 extends keyof U<U<T[K1]>[K2]>,
K4 extends keyof U<U<U<T[K1]>[K2]>[K3]>,
K5 extends keyof U<U<U<U<T[K1]>[K2]>[K3]>[K4]>
K5 extends keyof U<U<U<U<T[K1]>[K2]>[K3]>[K4]>,
R
> = T extends any[]
? T
: Pick<T, Exclude<keyof T, K1>> &
{
[KK1 in K1]-?: Required<
{ [key in K1]: FpSet4<U<T[K1]>, K2, K3, K4, K5> }
>[KK1]
[KK1 in K1]-?: { [key in K1]: FpSet4<U<T[K1]>, K2, K3, K4, K5, R> }[KK1]
}

// NOTE: TS doesn't allow partial generic type argument inference
// see: https://github.com/microsoft/TypeScript/pull/26349
// see: https://medium.com/@nandiinbao/partial-type-argument-inference-in-typescript-and-workarounds-for-it-d7c772788b2e
interface FpSetFnReturn<T> {
<K1 extends keyof T>(path: [K1], value: T[K1]): (
<K1 extends keyof T, R extends T[K1]>(path: [K1], value: R): (
source: Optional<T>,
) => FpSet1<T, K1>
) => FpSet1<T, K1, R>

<K1 extends keyof T, K2 extends keyof U<T[K1]>>(
<K1 extends keyof T, K2 extends keyof U<T[K1]>, R extends U<T[K1]>[K2]>(
path: [K1, K2],
value: U<T[K1]>[K2],
): (source: Optional<T>) => FpSet2<T, K1, K2>
value: R,
): (source: Optional<T>) => FpSet2<T, K1, K2, R>

<
K1 extends keyof T,
K2 extends keyof U<T[K1]>,
K3 extends keyof U<U<T[K1]>[K2]>
K3 extends keyof U<U<T[K1]>[K2]>,
R extends U<U<T[K1]>[K2]>[K3]
>(
path: [K1, K2, K3],
value: U<U<T[K1]>[K2]>[K3],
): (source: Optional<T>) => FpSet3<T, K1, K2, K3>
value: R,
): (source: Optional<T>) => FpSet3<T, K1, K2, K3, R>

<
K1 extends keyof T,
K2 extends keyof U<T[K1]>,
K3 extends keyof U<U<T[K1]>[K2]>,
K4 extends keyof U<U<U<T[K1]>[K2]>[K3]>
K4 extends keyof U<U<U<T[K1]>[K2]>[K3]>,
R extends U<U<U<T[K1]>[K2]>[K3]>[K4]
>(
path: [K1, K2, K3, K4],
value: U<U<U<T[K1]>[K2]>[K3]>[K4],
): (source: Optional<T>) => FpSet4<T, K1, K2, K3, K4>
value: R,
): (source: Optional<T>) => FpSet4<T, K1, K2, K3, K4, R>

<
K1 extends keyof T,
K2 extends keyof U<T[K1]>,
K3 extends keyof U<U<T[K1]>[K2]>,
K4 extends keyof U<U<U<T[K1]>[K2]>[K3]>,
K5 extends keyof U<U<U<U<T[K1]>[K2]>[K3]>[K4]>
K5 extends keyof U<U<U<U<T[K1]>[K2]>[K3]>[K4]>,
R extends U<U<U<U<T[K1]>[K2]>[K3]>[K4]>[K5]
>(
path: [K1, K2, K3, K4, K5],
value: U<U<U<U<T[K1]>[K2]>[K3]>[K4]>[K5],
): (source: Optional<T>) => FpSet5<T, K1, K2, K3, K4, K5>
value: R,
): (source: Optional<T>) => FpSet5<T, K1, K2, K3, K4, K5, R>
}

// NOTE: use private implementation because typedoc generates wrong documentation.
Expand Down
Loading