我有以下结构:<条码>ComboChartSpec> 和<条码>。 I m 界定处理<代码>的实用功能 ComboChartSpec。
如果我这样界定,它就会发挥作用。
function process1() {
const yAxisType = primary ;
const otherYAxisType = secondary ;
return {
[yAxisType]: foo,
[otherYAxisType]: bar
}
}
function process2() {
const yAxisType = secondary ;
const otherYAxisType = primary ;
return {
[yAxisType]: foo,
[otherYAxisType]: bar
}
}
我想合并这两个职能。 但是,我留下了TS错误。 我如何解决这一问题? 感谢!
function process(yAxisType: primary | secondary ) {
const otherYAxisType = yAxisType === primary ? secondary : primary ;
return {
[yAxisType]: foo,
[otherYAxisType]: bar
}
}
Type { [x: string]: { fields: never[]; } | { type: "quantitative"; }; scale: { type: "quantitative"; }; } is not assignable to type ComboChartAxisEncoding<"editor"> .
Type { [x: string]: { fields: never[]; } | { type: "quantitative"; }; scale: { type: "quantitative"; }; } is not assignable to type ComboChartSingleAxisEncoding<"editor"> .
Type { [x: string]: { fields: never[]; } | { type: "quantitative"; }; scale: { type: "quantitative"; }; } is missing the following properties from type { primary: ComboChartSingleAxisSectionEncoding<"editor">; secondary: ComboChartSingleAxisSectionEncoding<"editor">; scale: QuantitativeScale; } : primary, secondaryts(2322)
index.ts(85, 3): The expected type comes from property y which is declared here on type ComboChartEncodingMap<"editor">