Thanks to visit codestin.com
Credit goes to github.com

Skip to content

withParser is not applied for record values #496

@lucyydotp

Description

@lucyydotp

Hi, I'm trying to use a custom parser for the value type of a record, but it looks like the original value is being included in the output instead of the parsed value. This is causing typing issues, as the parser is interpreted correctly by TS, but the actual parsed value does not match.

import * as r from "runtypes";

const schema = r.Record(
	r.String,
	r.Array(r.String).withParser((arr) => new Set(arr)),
);

const parsed = schema.parse({
	key: ['value1', 'value2']
})

console.log(parsed.key?.constructor.name); // logs Array

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions