# If in a typedef

**URL:** <https://community.haxe.org/t/if-in-a-typedef/1040>\
**Category:** Haxe\
**Tags:** haxe-js\
**Created:** [September 6, 2018, 9:14am UTC](https://community.haxe.org/t/if-in-a-typedef/1040 "2018-09-06T09:14:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![axelhuizinga](https://community.haxe.org/user_avatar/community.haxe.org/axelhuizinga/32/1901_2.png) [@axelhuizinga](https://community.haxe.org/u/axelhuizinga)\
**Post date:** [September 6, 2018, 9:14am UTC](https://community.haxe.org/t/if-in-a-typedef/1040/1 "2018-09-06T09:14:00Z")

</div>

how would I declare such a type in haxe?

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

```

---

<div class="post-metadata">

**Author:** ![kLabz](https://community.haxe.org/user_avatar/community.haxe.org/klabz/32/225_2.png) [@kLabz](https://community.haxe.org/u/kLabz)\
**Post date:** [September 6, 2018, 10:12am UTC](https://community.haxe.org/t/if-in-a-typedef/1040/2 "2018-09-06T10:12:48Z")

</div>

Short answer: `typedef FormikTouched = Dynamic`

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

---

<div class="post-metadata">

**Author:** ![mark.knol](https://community.haxe.org/user_avatar/community.haxe.org/mark.knol/32/50_2.png) [@mark.knol](https://community.haxe.org/u/mark.knol)\
**Post date:** [September 7, 2018, 10:08am UTC](https://community.haxe.org/t/if-in-a-typedef/1040/3 "2018-09-07T10:08:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kLabz](https://community.haxe.org/user_avatar/community.haxe.org/klabz/32/225_2.png) [@kLabz](https://community.haxe.org/u/kLabz)\
**Post date:** [September 7, 2018, 10:17am UTC](https://community.haxe.org/t/if-in-a-typedef/1040/4 "2018-09-07T10:17:02Z")

</div>

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:

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

```

Which would not work with `Any`.
