-
-
Couldn't load subscription status.
- Fork 4.7k
Closed
Description
Describe the problem
Currently getContext returns unknown if no explicit type is provided.

Describe the proposed solution
Taking inspiration from svelte-typed-context, getContext can accept an InjectionKey<T>ContextKey<T> and return T:

This will improve type safety and can be done in a backwards compatible way.
The implementation would be just to add a new signature to getContext, setContext and hasContext
export interface ContextKey<T = unknown> { }
export function setContext<T>(key: ContextKey<T>, context: T): void
// getContext ...
// hasContext ...
// check for full implementation here:
// https://github.com/KamenKolev/svelte-typed-context/blob/master/index.ts
// (published npm package does not include `hasContext`, so install only from github)Alternatives considered
Importance
nice to have
Search terms
typed context inject provide
olehmisar, anton-fomin, hanszoons, oscarhermoso, max-got and 13 moreCarlos-err406, rChaoz and RisaI