# 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.

![](/files/93ieQk3nVOTdjPX5Rp5m)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tsafe.dev/flip.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
