Skip to content

Commit 082a03a

Browse files
authored
Merge pull request #890 from chantouchsek/fix/889-return-types
Fix/889 return types
2 parents 21111a4 + ff7a3ee commit 082a03a

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/core/BaseService.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { SimpleObject } from '../types'
12
import type { AxiosError, AxiosInstance, Method, AxiosRequestConfig, AxiosResponse } from 'axios'
23
import type { IParseOptions } from 'qs'
34
import { isObject } from 'lodash'
@@ -23,7 +24,7 @@ export default class BaseService {
2324
ignoreQueryPrefix: true,
2425
}
2526

26-
constructor(readonly endpoint: string, public parameters: Record<string, any> = {}) {}
27+
constructor(readonly endpoint: string, public parameters: SimpleObject<any> = {}) {}
2728

2829
get $http() {
2930
return BaseService.$http
@@ -102,7 +103,7 @@ export default class BaseService {
102103
const { response } = error
103104
if (response && response.status === UNPROCESSABLE_ENTITY) {
104105
const { data } = response
105-
const validationErrors: Record<string, any> = {}
106+
const validationErrors: SimpleObject<any> = {}
106107
Object.assign(validationErrors, data[this.$errorProperty])
107108
this.onFail(validationErrors)
108109
}
@@ -131,7 +132,7 @@ export default class BaseService {
131132
return `${url}${query}`
132133
}
133134

134-
setParameters(parameters: Record<string, any>) {
135+
setParameters(parameters: SimpleObject<any>) {
135136
Object.keys(parameters).forEach((key) => {
136137
this.parameters[key] = parameters[key]
137138
})
@@ -166,7 +167,7 @@ export default class BaseService {
166167
return this
167168
}
168169

169-
onFail(errors: Record<string, any>) {
170+
onFail(errors: SimpleObject<any>) {
170171
this.errors.fill(errors)
171172
validator.fill(errors)
172173
}

src/core/Validator.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import type { SimpleObject } from '../types'
12
import { cloneDeep, get, has, omit } from 'lodash'
23
import { is, toCamelCase, toSnakeCase } from '../util'
34

45
class Validator {
56
public successful: boolean
67
public processing: boolean
78

8-
constructor(public errors: Record<string, any> = {}) {
9+
constructor(public errors: SimpleObject<any> = {}) {
910
this.processing = false
1011
this.successful = false
1112
}
@@ -24,7 +25,7 @@ class Validator {
2425
return is(Object.keys(this.errors), fields)
2526
}
2627

27-
first(field: string | string[]): string | Record<string, any> | undefined {
28+
first(field: string | string[]): string | undefined {
2829
if (Array.isArray(field)) {
2930
const fields = this.fields(field)
3031
let fd = ''
@@ -42,7 +43,7 @@ class Validator {
4243
}
4344
}
4445

45-
firstBy(obj: Record<string, any>, field?: string) {
46+
firstBy(obj: SimpleObject<any>, field?: string) {
4647
let value: string
4748
if (!field) {
4849
value = obj[Object.keys(obj)[0]]
@@ -64,7 +65,7 @@ class Validator {
6465
any(field: string[] = [], returnObject?: boolean) {
6566
const fields = this.fields(field)
6667
if (returnObject) {
67-
const errors: Record<string, any> = {}
68+
const errors: SimpleObject<any> = {}
6869
if (!fields.length) return {}
6970
for (const f of fields) {
7071
const val = this.get(f)
@@ -74,7 +75,7 @@ class Validator {
7475
return errors
7576
}
7677
if (!fields.length) return Object.keys(this.errors).length > 0
77-
const errors: Record<string, any> = {}
78+
const errors: SimpleObject<any> = {}
7879
fields.forEach((key: string) => (errors[key] = this.get(key)))
7980
return Object.keys(errors).length > 0
8081
}
@@ -91,7 +92,7 @@ class Validator {
9192
return Object.keys(this.errors).length
9293
}
9394

94-
fill(errors: Record<string, any>) {
95+
fill(errors: SimpleObject<any>) {
9596
this.errors = errors
9697
}
9798

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type SimpleObject<V> = Record<string, V>

0 commit comments

Comments
 (0)