mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -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;
|
||||
}
|
||||
|
||||
export const dynamicComponent = <T extends typeof SvelteComponentDev>(component: T) => <
|
||||
U extends NonNullable<ConstructorParameters<T>[0]["props"]>,
|
||||
V extends string = never
|
||||
export const dynamicComponent = <Comp extends typeof SvelteComponentDev>(component: Comp) => <
|
||||
Props extends NonNullable<ConstructorParameters<Comp>[0]["props"]>,
|
||||
Lazy extends string = never
|
||||
>(
|
||||
props: Omit<U, V>,
|
||||
lazyProps: { [Property in keyof Pick<U, V>]: () => Pick<U, V>[Property] }
|
||||
): DynamicSvelteComponent<T> & U => {
|
||||
props: Omit<Props, Lazy>,
|
||||
lazyProps: { [Property in keyof Pick<Props, Lazy>]: () => Pick<Props, Lazy>[Property] }
|
||||
): DynamicSvelteComponent<Comp> & Props => {
|
||||
const dynamicComponent = { component, ...props };
|
||||
|
||||
for (const property in lazyProps) {
|
||||
const get = lazyProps[property];
|
||||
const propertyDescriptor: TypedPropertyDescriptor<
|
||||
Pick<U, V>[Extract<keyof Pick<U, V>, string>]
|
||||
Pick<Props, Lazy>[Extract<keyof Pick<Props, Lazy>, string>]
|
||||
> = { get, enumerable: true };
|
||||
Object.defineProperty(dynamicComponent, property, propertyDescriptor);
|
||||
}
|
||||
|
||||
return dynamicComponent as DynamicSvelteComponent<T> & U;
|
||||
return dynamicComponent as DynamicSvelteComponent<Comp> & Props;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue