Skip to content

Commit

Permalink
Bug Fix: fix Record.updateAt and Record.modifyAt signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jan 7, 2020
1 parent 38d78c4 commit 0077498
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/modules/Record.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ Added in v2.0.0
**Signature**

```ts
export function modifyAt<K extends string, A>(k: K, f: (a: A) => A): (r: Record<K, A>) => Option<Record<K, A>> { ... }
export function modifyAt<A>(k: string, f: (a: A) => A): <K extends string>(r: Record<K, A>) => Option<Record<K, A>> { ... }
```

Added in v2.0.0
Expand Down Expand Up @@ -648,7 +648,7 @@ Added in v2.0.0
**Signature**

```ts
export function updateAt<K extends string, A>(k: K, a: A): (r: Record<K, A>) => Option<Record<K, A>> { ... }
export function updateAt<A>(k: string, a: A): <K extends string>(r: Record<K, A>) => Option<Record<K, A>> { ... }
```

Added in v2.0.0
Expand Down
18 changes: 18 additions & 0 deletions dtslint/ts3.5/Record.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { pipe } from '../../src/pipeable'
import * as R from '../../src/Record'
import { identity } from '../../src/function'

declare const dictionaryString: { [key: string]: number }
declare const recordString: Record<string, number>
Expand All @@ -19,3 +21,19 @@ if (R.hasOwnProperty(keyString, recordString)) {
if (R.hasOwnProperty(keyString, recordStringEnum)) {
keyString // $ExpectType "a" | "b"
}

//
// updateAt
//

pipe(dictionaryString, R.updateAt('a', 3)) // $ExpectType Option<Record<string, number>>
pipe(recordString, R.updateAt('a', 3)) // $ExpectType Option<Record<string, number>>
pipe(recordStringEnum, R.updateAt('a', 3)) // $ExpectType Option<Record<"a" | "b", number>>

//
// modifyAt
//

pipe(dictionaryString, R.modifyAt('a', identity)) // $ExpectType Option<Record<string, number>>
pipe(recordString, R.modifyAt('a', identity)) // $ExpectType Option<Record<string, number>>
pipe(recordStringEnum, R.modifyAt('a', identity)) // $ExpectType Option<Record<"a" | "b", number>>
4 changes: 2 additions & 2 deletions src/Record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function deleteAt(k: string): <A>(r: Record<string, A>) => Record<string,
/**
* @since 2.0.0
*/
export function updateAt<K extends string, A>(k: K, a: A): (r: Record<K, A>) => Option<Record<K, A>> {
export function updateAt<A>(k: string, a: A): <K extends string>(r: Record<K, A>) => Option<Record<K, A>> {
return r => {
if (!hasOwnProperty(k, r)) {
return none
Expand All @@ -187,7 +187,7 @@ export function updateAt<K extends string, A>(k: K, a: A): (r: Record<K, A>) =>
/**
* @since 2.0.0
*/
export function modifyAt<K extends string, A>(k: K, f: (a: A) => A): (r: Record<K, A>) => Option<Record<K, A>> {
export function modifyAt<A>(k: string, f: (a: A) => A): <K extends string>(r: Record<K, A>) => Option<Record<K, A>> {
return r => {
if (!hasOwnProperty(k, r)) {
return none
Expand Down

0 comments on commit 0077498

Please sign in to comment.