# @288-toolkit/typed-context

> Wraps typed versions of Svelte's `getContext` and `setContext` functions with the provided type argument and context key.

Latest version **4.0.0** (published 2024-11-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @288-toolkit/typed-context
pnpm add @288-toolkit/typed-context
yarn add @288-toolkit/typed-context
bun add @288-toolkit/typed-context
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2024-11-01 |
| First published | 2024-04-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 2.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | DeuxHuitHuit |
| Maintainers | nitriques, f-elix |

## Links

- npm: https://www.npmjs.com/package/@288-toolkit/typed-context
- npm.io page: https://npm.io/package/@288-toolkit/typed-context

## Recent versions

- 4.0.0 (latest) — 2024-11-01
- 3.0.0 — 2024-04-30
- 1.0.2 — 2024-04-25
- 1.0.1 — 2024-04-24
- 1.0.0 — 2024-04-23

## README

# Typed-context

Wraps typed versions of Svelte's `getContext` and `setContext` functions with the provided type
argument and context key.

## Usage

`my-context.ts`

```ts
import { createTypedContext } from '@288-toolkit/typed-context';

type MyContext = {
	hello: string;
};

export const { getContext, setContext } = createTypedContext<MyContext>('my-context');
```

`my-parent-component.ts`

```svelte
<script lang="ts">
	import { setContext } from './my-context.ts';

	setContext({
		hello: 'world',
		other: 'prop' // Type error
	});
</script>
```

`my-child-component.ts`

```svelte
<script lang="ts">
	import { getContext } from './my-context.ts';

	const ctx = getContext();

	console.log(ctx.hello); // 'world'
	console.log(ctx.other); // Type error
</script>
```

---
_Source: https://npm.io/package/@288-toolkit/typed-context · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
