# Context

```ts
interface Context<T> extends Operation<T>
```

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

When used as an operation, it gets the value of the Context from
the current scope. If it has not been set, and there is no default
value, then a `MissingContextError` will be raised.

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


### 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">**key**<span class="inline-block bg-orange-100 rounded px-2 text-sm text-orange-900 mx-1">readonly</span>: 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-orange-100 rounded px-2 text-sm text-orange-900 mx-1">readonly</span><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 of the context if has not been defined for the current operation.
</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="set" class="inline scroll-mt-[100px]">set</h4>(**value**: T): [Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;T&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Set the value of the Context for the current scope.
</dd>
<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/v3/Operation.md)&lt;T | undefined&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Get the value of the Context from the current scope. If it has not been
set, and there is no default value, then this will return `undefined`.

</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/v3/Operation.md)&lt;T&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Get the value of the Context from the current scope. An error will be raised if the
context has not been defined.

</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/v3/Operation.md)&lt;R&gt;): [Operation](https://frontside.com/effection/api/v3/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-v3.6.1/lib/types.ts#L280)
