Skip to content

Defaulted is not coerced through validate #1292

@BuyMyBeard

Description

@BuyMyBeard

Take the following code snippet:

const [err, data] = validate({str: 'str'}, object({str: string(), def: defaulted(string(), '')}));
console.log(err);
console.log(data);

The previous code will have this error message in the err object: StructError: At path: def -- Expected a string, but received: undefined.

Now take this code snippet instead:

create({str: 'str'}, object({str: string(), def: defaulted(string(), '')}));

This code works perfectly.

According to the tsdoc included with validate Validate a value against a struct, returning an error if invalid, or the value (with potential coercion) if valid., the value should still be coerced by defaulted, just like create.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions