COMMUNITY

If in a typedef

haxe-js

(Axel Huizinga) #1

how would I declare such a type in haxe?

export declare type FormikTouched<Values> = {
    [K in keyof Values]?: Values[K] extends object ? FormikTouched<Values[K]> : boolean;
};

(Rudy Ges) #2

Short answer: typedef FormikTouched = Dynamic

Slightly longer answer: with a const type parameter and a genericMacro building fields from it.


(Mark) #3

I think it is in most cases better to use the Any type instead of Dynamic


(Rudy Ges) #4

I think it is one of the other cases here, though.

If I understand correctly, the ? in [K in keyof Values]?: means the fields are optional, so you could have to write something like this:

var a:FormikTouched<Whatever> = {};
a.whatever = true;

Which would not work with Any.