-
-
Save MiKolka7/d6db11024f4106e888a47cc7b3d16c3f to your computer and use it in GitHub Desktop.
Declare interface Vuex commit without undefined params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CommitOptions } from 'vuex' | |
export declare type OmitByValue<T, ValueType> = Pick<T, { | |
[Key in keyof T]: T[Key] extends ValueType ? never : Key; | |
}[keyof T]>; | |
export declare type PickByValue<T, ValueType> = Pick<T, { | |
[Key in keyof T]: T[Key] extends ValueType ? Key : never; | |
}[keyof T]>; | |
type User = { | |
id: number | |
} | |
type MutationTypes = { | |
COMMON_INIT_USER: User | |
COMMON_CLEAR: undefined | |
} | |
type MutationWithParams = OmitByValue<MutationTypes, undefined> | |
type MutationWithoutParams = PickByValue<MutationTypes, undefined> | |
interface Commit { | |
<Key extends keyof MutationWithParams>( | |
name: Key, | |
payload: MutationTypes[Key], | |
options?: CommitOptions, | |
): void | |
<Key extends keyof MutationWithoutParams>( | |
name: Key, | |
payload?: undefined, | |
options?: CommitOptions, | |
): void | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment