Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core/d.ts): support createStoreWithThis's type inference #631

Merged
merged 14 commits into from Nov 2, 2020

Conversation

anotherso1a
Copy link
Collaborator

image
image
image

interface StoreOptWithThis<S, G, M, A, D extends Deps> {
state?: S
getters?: G & ThisType<{ state: S & UnboxDepsField<D, 'state'>, getters: G & UnboxDepsField<D, 'getters'>, rootState: any }>
getters?: G & ThisType<{ state: S & UnboxDepsField<D, 'state'>, getters: GetGetters<G> & UnboxDepsField<D, 'getters'>, rootState: any }>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是,GetComputedType,之前采用的G是由于ts推动能力限制

@@ -403,9 +435,23 @@ declare class StoreWithThis<S = {}, G = {}, M = {}, A = {}, D extends Deps = {}>

export function createStoreWithThis<S = {}, G = {}, M extends MutationsAndActionsWithThis = {}, A extends MutationsAndActionsWithThis = {}, D extends Deps = {}> (option: StoreOptWithThis<S, G, M, A, D>): StoreWithThis<S, G, M, A, D>

// auxiliary functions
export function createState<S = {}> (state: S): S
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state没有类型推导没必要提供该函数


export function injectMixins (mixins: object | Array<object>, type?: 'app' | 'page' | 'component'): void
export function createGetters<S = {}, D extends Deps = {}, G = {}> (state: S, getters: G & ThisType<{ state: S & UnboxDepsField<D, 'state'>, getters: GetGetters<G> & UnboxDepsField<D, 'getters'>, rootState: any }>, deps?: D): G
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改名为createGettersWithThis吧,下面同理

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同样需要用GetComputedType而不是GetGetters


type GetAllActionsKey<A, D extends Deps, AK extends 'actions'|'mutations'> = RemoveProps<{
[K in StringKeyof<A>]: K extends keyof A ? A[K] : never
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不能直接A[K]么

@@ -87,6 +87,12 @@ type UnionToIntersection<U> = (U extends any
? I
: never;

type RemoveProps<T, D> = UnionToIntersection<Exclude<{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我想想有啥其他写法没

}

// Store Type Bindings
type StringKeyof<T> = `${Exclude<keyof T, symbol>}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块应该不需要字符串模板包装?

@hiyuki hiyuki merged commit c45446a into master Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants