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
Conversation
anotherso1a
commented
Oct 29, 2020
packages/core/@types/index.d.ts
Outdated
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 }> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该是,GetComputedType,之前采用的G是由于ts推动能力限制
packages/core/@types/index.d.ts
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state没有类型推导没必要提供该函数
packages/core/@types/index.d.ts
Outdated
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改名为createGettersWithThis吧,下面同理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同样需要用GetComputedType而不是GetGetters
packages/core/@types/index.d.ts
Outdated
|
||
type GetAllActionsKey<A, D extends Deps, AK extends 'actions'|'mutations'> = RemoveProps<{ | ||
[K in StringKeyof<A>]: K extends keyof A ? A[K] : never |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不能直接A[K]么
packages/core/@types/index.d.ts
Outdated
@@ -87,6 +87,12 @@ type UnionToIntersection<U> = (U extends any | |||
? I | |||
: never; | |||
|
|||
type RemoveProps<T, D> = UnionToIntersection<Exclude<{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我想想有啥其他写法没
packages/core/@types/index.d.ts
Outdated
} | ||
|
||
// Store Type Bindings | ||
type StringKeyof<T> = `${Exclude<keyof T, symbol>}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块应该不需要字符串模板包装?