fix(lite/types): issue with createUseCollection typing in VSCode

This commit is contained in:
Thierry
2023-09-05 17:02:44 +02:00
committed by Mathieu
parent 5448452b71
commit 2c5706a89b

View File

@@ -1,37 +1,62 @@
import { type StoreDefinition, storeToRefs } from "pinia";
import { computed, type ComputedRef, onUnmounted, type ToRefs } from "vue";
import type {
PiniaCustomStateProperties,
Store,
StoreDefinition,
StoreGetters,
StoreState,
} from "pinia";
import { storeToRefs } from "pinia";
import type { ComputedRef, Ref, ToRef, ToRefs } from "vue";
import { computed, onUnmounted } from "vue";
type IgnoredProperties =
| "_customProperties"
| "$id"
| "$dispose"
| "$state"
| "$patch"
| "$reset"
| "$subscribe"
| "$unsubscribe"
| "$onAction"
| "add"
| "remove"
| "subscribe"
| "hasSubscribers"
| "unsubscribe";
type ToComputedRefs<T> = {
[K in keyof T]: ToRef<T[K]> extends Ref<infer U>
? ComputedRef<U>
: ToRef<T[K]>;
};
type StoreToRefs<SS extends Store<any, any, any, any>> = ToRefs<
StoreState<SS> & PiniaCustomStateProperties<StoreState<SS>>
> &
ToComputedRefs<StoreGetters<SS>>;
type Output<
UseStore extends StoreDefinition,
Defer extends boolean,
> = UseStore extends StoreDefinition<
string,
infer State,
infer Getters,
infer Actions
>
? Omit<
ToRefs<State> & Getters & Actions,
"add" | "remove" | "subscribe" | "hasSubscribers" | "unsubscribe"
> &
(Defer extends true
? { start: () => void; isStarted: ComputedRef<boolean> }
: object)
: never;
S extends StoreDefinition<any, any, any, any>,
Defer extends boolean
> = Omit<S, keyof StoreToRefs<S> | IgnoredProperties> &
StoreToRefs<S> &
(Defer extends true
? { start: () => void; isStarted: ComputedRef<boolean> }
: object);
type SubscribableStore = StoreDefinition<
string,
any,
any,
{
subscribe: (id: symbol) => void;
unsubscribe: (id: symbol) => void;
hasSubscribers: boolean;
}
>;
export const createUseCollection = <UseStore extends SubscribableStore>(
useStore: UseStore
export const createUseCollection = <
SD extends StoreDefinition<any, any, any, any>,
UseStore extends SD extends StoreDefinition<
infer Id,
infer S,
infer G,
infer A
>
? Store<Id, S, G, A>
: never
>(
useStore: SD
) => {
return <Defer extends boolean>(options?: {
defer: Defer;