---
# System prepended metadata

title: 'Sending flow validation (cont.) - Fri 6th Nov, 2020'
tags: [C+, validation, useFormikContext, setFieldTouched, programmingjournal, setTimeout, exclude, '2020']

---

# Sending flow validation (cont.) - Fri 6th Nov, 2020

Continued with sending flow validation. Below are a few learnings.

Use `Exclude` in TypeScript to exclude a type from a union:

```typescript=
Exclude<MyType, 'thing'>
```

Biggest takeaway (and something I lost quite a few hours to) is [how Formik handles setFieldTouched and setFieldValue](https://github.com/formium/formik/issues/2083) from the `useFormikContext` hook. This is not a bug with Formik, but simply how React works.

The solution (unfortunately) is to use a `setTimeout` to force `setFieldTouched` to the end of the event loop:

```typescript=
setTimeout(() => setFieldTouched('recipients', true))
setFieldValue('recipients',
values.recipients.filter((recipient) => recipient.id !== user.id)
)
```

###### tags: `programmingjournal` `2020` `C+` `validation` `useFormikContext` `setTimeout` `setFieldTouched` `exclude`