# isAmong

Let's say we have an union type like:  <br>

{% code title="Names.ts" %}

```typescript
export const names = ["foo", "bar", "baz"] as const;
export type Name = typeof names[number];
```

{% endcode %}

isAmong enables to test if a given values is one of the names

```typescript
import { isAmong } from "tsafe/isAmong";
import { names, type Names } from "./Names";

declare value: "foo" | "bar" | "something else";

if( isAmong(names, value) ){
  // Here value is of type "foo" | "bar"
  // (the intesection of the type of value before the test and Name)
}
```

If we just have the type and not the exhausive array:

```typescript
import { assert, type Equals } from "tsafe/assert";
import { isAmong } from "tsafe/isAmong";
import type { Names } from "./Names";

const names = ["foo", "bar", "baz"] as const;

assert<Equals<typeof names, Names>>;

declare value: string;

if( isAmong(names, value) ){
   // Here value is of type Names
}
```


---

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