Skip to content

Commit 02502a3

Browse files
committed
Update types
1 parent 13ee227 commit 02502a3

File tree

8 files changed

+597
-641
lines changed

8 files changed

+597
-641
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = {
22
env: {
33
browser: true,
44
es6: true,
5+
es2020: true,
56
'jest/globals': true,
67
node: true,
78
},
@@ -14,7 +15,7 @@ module.exports = {
1415
],
1516
parser: '@typescript-eslint/parser',
1617
parserOptions: {
17-
ecmaVersion: 2018,
18+
ecmaVersion: 2019,
1819
project: ['tsconfig.eslint.json'],
1920
sourceType: 'module',
2021
projectFolderIgnoreList: ['dist'],

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Index<T> extends MeiliAxiosWrapper implements Types.IndexInterface<T> {
7676
async search<P extends Types.SearchParams<T>>(
7777
query?: string,
7878
options?: P,
79-
method: 'POST' | 'GET' = 'POST'
79+
method: Types.Methods = 'POST'
8080
): Promise<Types.SearchResponse<T, P>> {
8181
const url = `/indexes/${this.uid}/search`
8282
const params: Types.SearchRequest = {

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,16 @@ export interface MeiliSearchInterface extends MeiliAxiosWrapper {
251251
version: () => Promise<Version>
252252
}
253253

254+
export type Methods = 'POST' | 'GET'
255+
254256
export interface IndexInterface<T = any> extends MeiliAxiosWrapperInterface {
255257
uid: string
256258
getUpdateStatus: (updateId: number) => Promise<Update>
257259
getAllUpdateStatus: () => Promise<Update[]>
258260
search: <P extends SearchParams<T>>(
259261
query: string,
260262
options?: P,
261-
method?: 'POST' | 'GET'
263+
method?: Methods
262264
) => Promise<SearchResponse<T, P>>
263265
show: () => Promise<IndexResponse>
264266
updateIndex: (indexData: IndexOptions) => Promise<IndexResponse>

src/utils.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
function removeUndefinedFromObject(object: Record<string, any>): object {
2-
return Object.keys(object).reduce((acc: Record<string, any>, key: string) => {
3-
if (object[key] !== undefined) {
4-
acc[key] = object[key]
5-
}
6-
return acc
7-
}, {})
1+
function removeUndefinedFromObject(obj: object): object {
2+
// remove undefined
3+
const cleaned = Object.entries(obj).filter((x) => x[1] !== undefined)
4+
return Object.fromEntries(cleaned)
85
}
96

107
async function sleep(ms: number): Promise<void> {

0 commit comments

Comments
 (0)