mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
Give clearer type names to dynamicComponent
This commit is contained in:
parent
a2d37206ea
commit
bf33397855
1 changed files with 8 additions and 8 deletions
|
@ -6,22 +6,22 @@ export interface DynamicSvelteComponent<
|
||||||
component: T;
|
component: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const dynamicComponent = <T extends typeof SvelteComponentDev>(component: T) => <
|
export const dynamicComponent = <Comp extends typeof SvelteComponentDev>(component: Comp) => <
|
||||||
U extends NonNullable<ConstructorParameters<T>[0]["props"]>,
|
Props extends NonNullable<ConstructorParameters<Comp>[0]["props"]>,
|
||||||
V extends string = never
|
Lazy extends string = never
|
||||||
>(
|
>(
|
||||||
props: Omit<U, V>,
|
props: Omit<Props, Lazy>,
|
||||||
lazyProps: { [Property in keyof Pick<U, V>]: () => Pick<U, V>[Property] }
|
lazyProps: { [Property in keyof Pick<Props, Lazy>]: () => Pick<Props, Lazy>[Property] }
|
||||||
): DynamicSvelteComponent<T> & U => {
|
): DynamicSvelteComponent<Comp> & Props => {
|
||||||
const dynamicComponent = { component, ...props };
|
const dynamicComponent = { component, ...props };
|
||||||
|
|
||||||
for (const property in lazyProps) {
|
for (const property in lazyProps) {
|
||||||
const get = lazyProps[property];
|
const get = lazyProps[property];
|
||||||
const propertyDescriptor: TypedPropertyDescriptor<
|
const propertyDescriptor: TypedPropertyDescriptor<
|
||||||
Pick<U, V>[Extract<keyof Pick<U, V>, string>]
|
Pick<Props, Lazy>[Extract<keyof Pick<Props, Lazy>, string>]
|
||||||
> = { get, enumerable: true };
|
> = { get, enumerable: true };
|
||||||
Object.defineProperty(dynamicComponent, property, propertyDescriptor);
|
Object.defineProperty(dynamicComponent, property, propertyDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dynamicComponent as DynamicSvelteComponent<T> & U;
|
return dynamicComponent as DynamicSvelteComponent<Comp> & Props;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue