import type { InjectionKey, Ref } from 'vue'; import { inject as vueInject, provide as vueProvide } from 'vue'; import type { Org, OrgPermissions, Repo } from '~/lib/api/types'; export interface InjectKeys { repo: Ref; org: Ref; 'org-permissions': Ref; } export function inject(key: T): InjectKeys[T] { const value = vueInject(key); if (value === undefined) { throw new Error(`Please provide a value for ${key}`); } return value; } export function provide(key: T, value: InjectKeys[T]): void { return vueProvide(key, value as T extends InjectionKey ? V : InjectKeys[T]); }