typed-inject
Version:
Type safe dependency injection framework for TypeScript
15 lines (13 loc) • 398 B
text/typescript
// Forces typescript to explicitly calculate the complicated type
export type Simplify<T> = {} & { [K in keyof T]: T[K] };
export type TChildContext<
TParentContext,
TProvided,
CurrentToken extends string,
> = Simplify<{
[K in keyof TParentContext | CurrentToken]: K extends CurrentToken //
? TProvided
: K extends keyof TParentContext
? TParentContext[K]
: never;
}>;