import { inject, type InjectionKey, provide } from "vue" export const makeContext: { (def: T): { use: () => T provide: (locale: T) => void } (def?: T): { use: () => T | undefined provide: (locale: T) => void } } = (def?: T) => { const key = Symbol() as InjectionKey return { use: () => inject(key, def), provide: (locale: T) => provide(key, locale) } } export const injectCertain = (key: InjectionKey) => { const v = inject(key) if (v === undefined) { throw new Error(`Injectionkey ${key.toString()} not found`) } return v } export const makeContextCertain = () => { const key = Symbol() as InjectionKey return { use: () => injectCertain(key), provide: (locale: T) => provide(key, locale) } }