Skip to content

Fix ValidatorFunc Type Mistake#1998

Open
foolishflyfox wants to merge 1 commit intokonvajs:masterfrom
foolishflyfox:fix-ValidatorFunc-type-mistake
Open

Fix ValidatorFunc Type Mistake#1998
foolishflyfox wants to merge 1 commit intokonvajs:masterfrom
foolishflyfox:fix-ValidatorFunc-type-mistake

Conversation

@foolishflyfox
Copy link
Copy Markdown

The ValidatorFunc defined in Factory.ts has a mistake.

For Example:

addGetterSetter<T extends Constructor, U extends Attr<T>>(
    constructor: T,
    attr: U,
    def?: Value<T, U>,
    validator?: ValidatorFunc<Value<T, U>>,
    after?: AfterFunc<T>
)

because Value<T, U> has do ExtractGetSet

type Value<T extends Constructor, U extends Attr<T>> = ExtractGetSet<InstanceType<T>[U]>

but ValidatorFunc do ExtractGetSet again:

type ValidatorFunc<T> = (val: ExtractGetSet<T>, attr: string) => T;

so, the val is always never, and with VSCode can see this phenomenon:

image

my change can fix this mistake:

image

@lavrton
Copy link
Copy Markdown
Member

lavrton commented Dec 30, 2025

Well, in validator, val should be any. never is not correct. And in that example number is not correct as well, because validator should check any value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants