From: Eduardo San Martin Morote Date: Fri, 24 Dec 2021 14:17:42 +0000 (+0100) Subject: refactor: export internal types X-Git-Tag: @pinia/nuxt@0.1.8~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=647373ec74e119ba225ffb547419e6c323cc0787;p=thirdparty%2Fvuejs%2Fpinia.git refactor: export internal types --- diff --git a/packages/pinia/src/index.ts b/packages/pinia/src/index.ts index 99fbd400..58b1f4a7 100644 --- a/packages/pinia/src/index.ts +++ b/packages/pinia/src/index.ts @@ -27,6 +27,7 @@ export type { _StoreWithState, StoreProperties, StoreOnActionListener, + _StoreOnActionListenerContext, StoreOnActionListenerContext, SubscriptionCallback, SubscriptionCallbackMutation, @@ -40,6 +41,14 @@ export type { DefineStoreOptions, DefineSetupStoreOptions, DefineStoreOptionsInPlugin, + _ExtractActionsFromSetupStore, + _ExtractGettersFromSetupStore, + _ExtractStateFromSetupStore, + _DeepPartial, + _ExtractActionsFromSetupStore_Keys, + _ExtractGettersFromSetupStore_Keys, + _ExtractStateFromSetupStore_Keys, + _UnwrapAll, } from './types' export { MutationType } from './types' diff --git a/packages/pinia/src/store.ts b/packages/pinia/src/store.ts index 33415b3d..5a23b475 100644 --- a/packages/pinia/src/store.ts +++ b/packages/pinia/src/store.ts @@ -26,7 +26,7 @@ import { import { StateTree, SubscriptionCallback, - DeepPartial, + _DeepPartial, isPlainObject, Store, _Method, @@ -55,7 +55,7 @@ type _ArrayType = AT extends Array ? T : never function mergeReactiveObjects( target: T, - patchToApply: DeepPartial + patchToApply: _DeepPartial ): T { // no need to go through symbols because they cannot be serialized anyway for (const key in patchToApply) { @@ -250,10 +250,10 @@ function createSetupStore< const hotState = ref({} as S) function $patch(stateMutation: (state: UnwrapRef) => void): void - function $patch(partialState: DeepPartial>): void + function $patch(partialState: _DeepPartial>): void function $patch( partialStateOrMutator: - | DeepPartial> + | _DeepPartial> | ((state: UnwrapRef) => void) ): void { let subscriptionMutation: SubscriptionCallbackMutation diff --git a/packages/pinia/src/types.ts b/packages/pinia/src/types.ts index ab21cd3a..5b2d3dad 100644 --- a/packages/pinia/src/types.ts +++ b/packages/pinia/src/types.ts @@ -32,7 +32,7 @@ export function isPlainObject( * * @internal */ -export type DeepPartial = { [K in keyof T]?: DeepPartial } +export type _DeepPartial = { [K in keyof T]?: _DeepPartial } // type DeepReadonly = { readonly [P in keyof T]: DeepReadonly } // TODO: can we change these to numbers? @@ -112,7 +112,7 @@ export interface SubscriptionCallbackMutationPatchObject /** * Object passed to `store.$patch()`. */ - payload: DeepPartial + payload: _DeepPartial } /** @@ -142,8 +142,6 @@ export type SubscriptionCallbackMutation = | SubscriptionCallbackMutationPatchObject | SubscriptionCallbackMutationPatchFunction -export type UnwrapPromise = T extends Promise ? V : T - /** * Callback of a subscription */ @@ -164,8 +162,13 @@ export type SubscriptionCallback = ( /** * Actual type for {@link StoreOnActionListenerContext}. Exists for refactoring * purposes. For internal use only. + * @internal */ -interface _StoreOnActionListenerContext { +export interface _StoreOnActionListenerContext< + Store, + ActionName extends string, + A +> { /** * Name of the action */ @@ -191,12 +194,12 @@ interface _StoreOnActionListenerContext { after: ( callback: A extends Record ? ( - resolvedReturn: UnwrapPromise> + resolvedReturn: Awaited> // allow the after callback to override the return value ) => | void | ReturnType - | UnwrapPromise> + | Awaited> : () => void ) => void @@ -328,7 +331,7 @@ export interface _StoreWithState< * * @param partialState - patch to apply to the state */ - $patch(partialState: DeepPartial>): void + $patch(partialState: _DeepPartial>): void /** * Group multiple changes into one function. Useful when mutating objects like @@ -544,30 +547,34 @@ export type _GettersTree = Record< export type _ActionsTree = Record /** + * Type that enables refactoring through IDE. * @internal */ -type _ExtractStateFromSetupStore_Keys = keyof { +export type _ExtractStateFromSetupStore_Keys = keyof { [K in keyof SS as SS[K] extends _Method | ComputedRef ? never : K]: any } /** + * Type that enables refactoring through IDE. * @internal */ -type _ExtractActionsFromSetupStore_Keys = keyof { +export type _ExtractActionsFromSetupStore_Keys = keyof { [K in keyof SS as SS[K] extends _Method ? K : never]: any } /** + * Type that enables refactoring through IDE. * @internal */ -type _ExtractGettersFromSetupStore_Keys = keyof { +export type _ExtractGettersFromSetupStore_Keys = keyof { [K in keyof SS as SS[K] extends ComputedRef ? K : never]: any } /** + * Type that enables refactoring through IDE. * @internal */ -type _UnwrapAll = { [K in keyof SS]: UnwrapRef } +export type _UnwrapAll = { [K in keyof SS]: UnwrapRef } /** * @internal