# Context

```ts
interface Context<T>
```

`Context` defines a value which is in effect for a given scope which is an
(action, resource, call, or spawn).

Unless a context value is defined for a particular scope, it will inherit
its value from its parent scope.

### Examples
#### Example 1
```ts
let User = createContext<string>("user");
yield* User.set("alice");
console.log(yield* User.expect()); // "alice"
```
---


### Type Parameters
T


### Properties
<dl>
<dt class="border-dotted dark:border-blue-900 [&:not(:first-child)]:border-t-1 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2">**name**: string</dt>
<dd class="flex flex-col [&>pre]:mb-3">
A unique identifier for this context.
</dd>
<dt class="border-dotted dark:border-blue-900 [&:not(:first-child)]:border-t-1 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2">**defaultValue**<span class="inline-block bg-sky-100 rounded px-2 text-sm text-sky-900 mx-1">optional</span>: T</dt>
<dd class="flex flex-col [&>pre]:mb-3">
The value returned by this context when it is not present on a scop.e
</dd>
</dl>
### Methods
<dl>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="get" class="inline scroll-mt-[100px]">get</h4>(): [Operation](https://frontside.com/effection/api/v4/Operation.md)&lt;T | undefined&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Read the current value of this context if it exists.

</dd>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="set" class="inline scroll-mt-[100px]">set</h4>(**value**: T): [Operation](https://frontside.com/effection/api/v4/Operation.md)&lt;T&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Set the value of a context on the current scope. It will not effect the value of its
containing scope and will only be visible by this scope and its children.

</dd>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="expect" class="inline scroll-mt-[100px]">expect</h4>(): [Operation](https://frontside.com/effection/api/v4/Operation.md)&lt;T&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Read the current value of the context or fail if it does not exist

</dd>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="delete" class="inline scroll-mt-[100px]">delete</h4>(): [Operation](https://frontside.com/effection/api/v4/Operation.md)&lt;boolean&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Remove a context value from the current scope. This will only effect the current scope and
not its parent value.

</dd>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="with" class="inline scroll-mt-[100px]">with</h4>&lt;R&gt;(**value**: T, **operation**: (**value**: T) => [Operation](https://frontside.com/effection/api/v4/Operation.md)&lt;R&gt;): [Operation](https://frontside.com/effection/api/v4/Operation.md)&lt;R&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Evaluate an operation using `value` for the context. Once the operation is completed, the context
will be reverted to its original value, or removed if it was not present originally.

</dd>
</dl>

[View code](https://github.com/thefrontside/effection/tree/effection-v4.2.0/lib/types.ts#L224)
