3.0.0 • Published 27 days ago

@288-toolkit/typed-context v3.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
27 days ago

Typed-context

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

Usage

my-context.ts

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

type MyContext = {
	hello: string;
};

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

my-parent-component.ts

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

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

my-child-component.ts

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

	const ctx = getContext();

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

27 days ago

1.0.2

1 month ago

1.0.1

1 month ago

1.0.0

1 month ago