Skip to content

Commit b30e614

Browse files
committed
fix: remove wrong type JSONQueryPipe and fix the type definition of filter
1 parent 3ecfa47 commit b30e614

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/functions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const functions: FunctionBuildersMap = {
130130
}
131131
},
132132

133-
filter: <T>(predicate: JSONQuery[]) => {
133+
filter: <T>(predicate: JSONQuery) => {
134134
const _predicate = compile(predicate)
135135

136136
return (data: T[]) => data.filter((item) => truthy(_predicate(item)))
@@ -171,7 +171,7 @@ export const functions: FunctionBuildersMap = {
171171

172172
pick: (...properties: JSONQueryProperty[]) => {
173173
const getters = properties.map(
174-
([_get, ...path]) => [path[path.length - 1], functions.get(...path)] as Getter
174+
([_get, ...path]) => [path[path.length - 1], functions.get(...(path as JSONPath))] as Getter
175175
)
176176

177177
const _pick = (object: Record<string, unknown>, getters: Getter[]): unknown => {
@@ -294,7 +294,7 @@ export const functions: FunctionBuildersMap = {
294294
not: buildFunction((a: unknown) => !a),
295295

296296
exists: (queryGet: JSONQueryFunction) => {
297-
const parentPath = queryGet.slice(1)
297+
const parentPath = queryGet.slice(1) as JSONPath
298298
const key = parentPath.pop()
299299
const getter = functions.get(...parentPath)
300300

src/jsonquery.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export type {
2929
JSONQueryObject,
3030
JSONQueryOptions,
3131
JSONQueryParseOptions,
32-
JSONQueryPipe,
3332
JSONQueryPrimitive,
3433
JSONQueryProperty,
3534
JSONQueryStringifyOptions

src/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
export type JSONQueryPipe = JSONQuery[]
2-
export type JSONQueryFunction = [name: string, ...args: JSONQuery[]]
1+
export type JSONQueryFunction = [name: string, ...args: unknown[]]
32
export type JSONQueryObject = { [key: string]: JSONQuery }
43
export type JSONQueryPrimitive = string | number | boolean | null
5-
export type JSONQuery = JSONQueryFunction | JSONQueryPipe | JSONQueryObject | JSONQueryPrimitive
4+
export type JSONQuery = JSONQueryFunction | JSONQueryObject | JSONQueryPrimitive
65

76
export type JSONProperty = string
87
export type JSONPath = JSONProperty[]

0 commit comments

Comments
 (0)