Skip to content

Commit

Permalink
feat: fix ts
Browse files Browse the repository at this point in the history
  • Loading branch information
0529bill committed Aug 4, 2022
1 parent 84d410a commit cbab854
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ console.log(loginErrorObject);
2. dataSource: any (is isRequired if using customCondition)

3. errorArray: Array (isRequired)
- condition: Array (pick one between condition or customCondition)
- condition: (string | number | boolean | undefined | null)[] (pick one between condition or customCondition)
- customCondition: Function (pick one between condition or customCondition): (dataSource, returnArray) => [true, false....]
- index: string (isRequired): will be the key for the return error Object.
- errorMessage: string: will be the value for the return error message.
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface ErrorObject {
index: string
condition: boolean[]
condition: (string | number | boolean | undefined | null)[]
errorMessage?: string
// eslint-disable-next-line no-unused-vars
customCondition?: (dataSource: unknown, conditionReturnArray: boolean[]) => boolean[]
Expand All @@ -12,7 +12,7 @@ type ErrorResult = {
}

type ErrorValidation = {
[key: string | number]: ErrorResult | '' | string | (string | ErrorResult | null)[]
[key: string | number]: ErrorResult | '' | string | null | (string | ErrorResult | null)[]
}

const handleValidation = ({
Expand All @@ -30,7 +30,7 @@ const handleValidation = ({

// 接受 condition 為 [ condition1, condition2]
const handleValidateItem = (errorItem: ErrorObject) => {
if (errorItem.condition.every((error: boolean) => error !== false)) {
if (errorItem.condition.every((error) => error !== false)) {
return false
}
return true
Expand Down

0 comments on commit cbab854

Please sign in to comment.