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
actionA1({ commit, dispatch }, payload) { | |
commit('mutationA1', false); // ERROR: Argument of type 'boolean' is not assignable to parameter of type 'MutationA2Payload'. | |
dispatch('actionA2', false); // ERROR: Argument of type 'boolean' is not assignable to parameter of type 'ActionA2Payload'. | |
}, |
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
interface Module1Mutations { | |
mutationA1(state: Module1State, payload: MutationA1Payload): void | |
mutationA2(state: Module1State, payload: MutationA2Payload): void | |
} | |
export const module1Mutations: MutationTree<Module1State> & Module1Mutations = { | |
mutationA1(state, payload) {}, | |
mutationA2(state, payload) {}, | |
}; |
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
interface Module1Actions { | |
actionA1(context: Module1ActionContext, payload: ActionA1Payload): void | |
actionA2(context: Module1ActionContext, payload: ActionA2Payload): void | |
} | |
type Module1ActionContext = { | |
dispatch<K extends keyof Module1Actions>( | |
actionType: K, | |
payload: Parameters<Module1Actions[K]>[1], | |
options?: DispatchOptions, |
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
type Color = "red" | "blue"; | |
type Quantity = "one" | "two"; | |
type SeussFish = `${Quantity | Color} fish`; | |
// same as | |
// type SeussFish = "one fish" | "two fish" | |
// | "red fish" | "blue fish"; |
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
computed: { | |
mappedItems() { | |
return this.items.map(item => ({ | |
...item, | |
a: getA(item), | |
b: getB(item), | |
c: getC(item), | |
d: getD(item), | |
e: getE(item), | |
}); |
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
computed: { | |
mappedItems() { | |
return this.items.map(item => ({ | |
...item, | |
a: getA(item), | |
b: getB(item), | |
c: getC(item), | |
d: getD(item), | |
e: getE(item), | |
}); |
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
// Item.vue | |
...mapGetters('namespace', [ | |
'getA', | |
'getB', | |
'getC', | |
'getD', | |
'getE', | |
}); |
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
export enum BUTTON_SIZES_ENUM { | |
SMALL = 'small', | |
MEDIUM = 'medium', | |
LARGE = 'large', | |
} |
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
type ButonSizeKey = keyof typeof BUTTON_SIZES; // "SMALL" | "MEDIUM" | "LARGE" | |
type ButonSizeValue = typeof BUTTON_SIZES[ButonSizeKey] // "small" | "medium" | "large" |
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
let fn = (buttonSize: BUTTON_SIZES_UNION) => {}; | |
fn('small'); | |
fn('smal'); // Argument of type '"smal"' is not assignable to parameter of type 'BUTTON_SIZES_UNION' | |
let str: string; | |
fn(str); // Argument of type 'string' is not assignable to parameter of type 'BUTTON_SIZES_UNION'. |