# flip

## Quick Example:

```typescript
import { flip } from "tsafe/flip";

const obj = {
	is_: false,
};

flip(obj, "is_");

//obj.is_ is now set to true
```

## In more detail:

When you have an object that contains another object that contains a boolean, and you wish to flip the value of that boolean for example, you would usually do as follows.

```typescript
const obj = {
	innerObj: {
		is_: false,
		x: 44,
		y: 33,
	},
};

obj.innerObj.is_ = !obj.innerObj.is_;
```

With the `flip` function, the task will be a bit less tedious.

```typescript
flip(obj.innerObj, "is_");
```

The first argument is the object that contains the boolean value, and the second, is the key of the boolean property. Typescript will infer the key(s) of type boolean as illustrated below.

![](https://2070518381-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_DPR4G1FRgI3DwBvcp%2Fuploads%2Fgit-blob-fedd9798df4f6a03398162db0d14c62c34908670%2FScreenshot%202021-05-14%20at%2017.10.47.png?alt=media)
