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

superstruct's dynamic not working #2

Open
paolobrasolin opened this issue Dec 12, 2021 · 0 comments
Open

superstruct's dynamic not working #2

paolobrasolin opened this issue Dec 12, 2021 · 0 comments
Assignees
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@paolobrasolin
Copy link
Owner

When writing

if (index == 1) return max(Natural, main.length - 2);

I found out about ianstormtaylor/superstruct#830

Since it's already been solved in a pending PR ianstormtaylor/superstruct#966 I'll ust wait for merge.
In the meantime, I imported it as a patch here:

//=[ Monkeypatching ]===========================================================
// source: https://github.com/ianstormtaylor/superstruct/pull/966
// solves: https://github.com/ianstormtaylor/superstruct/issues/830
// TODO: remove when PR is merged
// NOTE: this is needed only by the bounded vertices count int MainItem
function dynamic<T>(
fn: (value: unknown, ctx: Context) => Struct<T, any>,
): Struct<T, null> {
return new Struct({
type: "dynamic",
schema: null,
*entries(value, ctx) {
const struct = fn(value, ctx);
yield* struct.entries(value, ctx);
},
validator(value, ctx) {
const struct = fn(value, ctx);
return struct.validator(value, ctx);
},
coercer(value, ctx) {
const struct = fn(value, ctx);
return struct.coercer(value, ctx);
},
refiner(value, ctx) {
const struct = fn(value, ctx);
return struct.refiner(value, ctx);
},
});
}

@paolobrasolin paolobrasolin added bug Something isn't working wontfix This will not be worked on labels Dec 12, 2021
@paolobrasolin paolobrasolin self-assigned this Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant