Skip to content

Instantly share code, notes, and snippets.

@MiKolka7

MiKolka7/.ts Secret

Last active Dec 10, 2019
Embed
What would you like to do?
Declare interface Vuex commit without undefined params
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