interface Options {
a: () => T;
b: (p: T) => void;
}
function defineItem(options: Options) {
return options;
}
const config = {
item1: defineItem({
a: () => ({ id: 1 }),
b: (params) => {}, // params 类型是 { id: number }
}),
item2: defineItem({
a: () => ({ name: '1' }),
b: (params) => {}, // params 类型是 { name: string }
}),
};
预期的效果
const config = defineConfig({
item1: {
a: () => ({ id: 1 }),
b: (params) => {}, // params 类型是 { id: number }
},
item2: {
a: () => ({ name: '1' }),
b: (params) => {}, // params 类型是 { name: string }
},
});