mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-29 20:43:37 +03:00
Prevent future DI bugs by throwing error
At present we never get optional dependencies, and if that was necessary we'd be explicit about it.
This commit is contained in:
parent
debfb48ba7
commit
d78f95417d
@ -4,11 +4,15 @@ import type { Readable } from 'svelte/store';
|
||||
export function getContextByClass<T extends new (...args: any) => InstanceType<T>>(
|
||||
key: T
|
||||
): InstanceType<T> {
|
||||
return svelteGetContext<InstanceType<T>>(key);
|
||||
const instance = svelteGetContext<InstanceType<T> | undefined>(key);
|
||||
if (!instance) throw new Error(`no instance of \`${key.name}\` in context`);
|
||||
return instance;
|
||||
}
|
||||
|
||||
export function getContextStoreByClass<T extends new (...args: any) => InstanceType<T>>(
|
||||
key: T
|
||||
): Readable<InstanceType<T>> {
|
||||
return svelteGetContext<Readable<InstanceType<T>>>(key);
|
||||
const instance = svelteGetContext<Readable<InstanceType<T>> | undefined>(key);
|
||||
if (!instance) throw new Error(`no instance of \`Readable<${key.name}>\` in context`);
|
||||
return instance;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user