Skip to content

Commit

Permalink
remove sloppyRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeck committed Dec 6, 2023
1 parent 6988517 commit f68b411
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 127 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
- add `nonStrict` combinator ([#90](https://github.com/hoeck/simple-runtypes/pull/90))
- `nonStrict` creates a non-strict `record` runtype from a provided `record` runtype
- a non-strict `record` runtype will ignore keys that are not specified in the original runtype's typemap
- non-strict `record` runtypes will replace `sloppyRecord` runtypes
- remove `sloppyRecord`
- replaced by `nonStrict`: `sloppyRecord(X)` -> `nonStrict(record(X))`
- fixes [#23](https://github.com/hoeck/simple-runtypes/issues/23)
- fix: allow literal booleans as type-discriminators in discriminated unions, see [#98](https://github.com/hoeck/simple-runtypes/issues/98)

### 7.1.3
Expand Down
25 changes: 0 additions & 25 deletions src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,3 @@ export function record<
> {
return internalRecord(typemap as any)
}

/**
* Like record but ignore unknown keys.
*
* Returns a new object that only contains the keys specified in the typemap.
* Additional keys are ignored.
*
* Keeps you save from unwanted propertiers and evil __proto__ injections.
*/
export function sloppyRecord<
T,
Typemap = { [K in keyof T]: Runtype<T[K]> | OptionalRuntype<T[K]> },
OptionalKeys extends keyof Typemap = {
[K in keyof Typemap]: Typemap[K] extends OptionalRuntype<any> ? K : never
}[keyof Typemap]
>(
typemap: Typemap,
): Runtype<
Collapse<
{ [K in Exclude<keyof Typemap, OptionalKeys>]: Unpack<Typemap[K]> } &
{ [K in OptionalKeys]?: Unpack<Typemap[K]> }
>
> {
return internalRecord(typemap as any, true)
}
101 changes: 0 additions & 101 deletions test/sloppyRecord.test.ts

This file was deleted.

0 comments on commit f68b411

Please sign in to comment.