Skip to content

Commit

Permalink
fix(deps): update dependency typescript to v4.8.2 (#886)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency typescript to v4.8.2

* fix: Corrects TS errors

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
ryasmi and renovate[bot] committed Sep 7, 2022
1 parent ef58bce commit 6f7fa4e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"semantic-release": "19.0.5",
"ts-jest": "28.0.8",
"ts-node": "10.9.1",
"typescript": "4.7.4"
"typescript": "4.8.2"
},
"jest": {
"preset": "ts-jest",
Expand Down
9 changes: 6 additions & 3 deletions src/valueRules/enum/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ export class InvalidEnumError<T> extends BaseError {

type Values<T> = T[keyof T]

export function isEnum<Output>(enumerator: Output, input: unknown): input is Values<Output> {
export function isEnum<Output extends { [s: string]: unknown }>(
enumerator: Output,
input: unknown
): input is Values<Output> {
const enumValues = Object.values(enumerator)
return enumValues.includes(input)
}

export function enumerated<Output>(enumerator: Output) {
export function enumerated<Output extends { [s: string]: unknown }>(enumerator: Output) {
return (input: unknown) => {
if (isEnum(enumerator, input)) {
return input as Values<Output>
}
const enumValues = Object.values(enumerator)
throw new InvalidEnumError<Values<Output>>(enumValues)
throw new InvalidEnumError(enumValues)
}
}

0 comments on commit 6f7fa4e

Please sign in to comment.