Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect refiner in dynamic and lazy #966

Merged
merged 2 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/structs/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export function dynamic<T>(
const struct = fn(value, ctx)
return struct.coercer(value, ctx)
},
refiner(value, ctx) {
const struct = fn(value, ctx)
return struct.refiner(value, ctx)
},
})
}

Expand Down Expand Up @@ -145,6 +149,10 @@ export function lazy<T>(fn: () => Struct<T, any>): Struct<T, null> {
struct ??= fn()
return struct.coercer(value, ctx)
},
refiner(value, ctx) {
struct ??= fn()
return struct.refiner(value, ctx)
},
})
}

Expand Down
15 changes: 15 additions & 0 deletions test/validation/dynamic/with-refiners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { dynamic, string, nonempty } from '../../..'

export const Struct = dynamic(() => nonempty(string()))

export const data = ''

export const failures = [
{
value: data,
type: 'string',
refinement: 'nonempty',
path: [],
branch: [data],
},
]
15 changes: 15 additions & 0 deletions test/validation/lazy/with-refiners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { lazy, nonempty, string } from '../../..'

export const Struct = lazy(() => nonempty(string()))

export const data = ''

export const failures = [
{
value: data,
type: 'string',
refinement: 'nonempty',
path: [],
branch: [data],
},
]