Kendo,TypeScript 定义错误:
Kendo, TypeScript definition bug:
我正在使用下面显示的语法(取自 http://demos.telerik.com/kendo-ui/bar-charts/index)在 TypeScript 文件中创建一个 Kendo 图表:
function createChart() {
$("#chart").kendoChart({
title: {
text: "Site Visitors Stats \n /thousands/"
},
legend: {
visible: false
},
seriesDefaults: {
type: "bar"
},
series: [{
name: "Total Visits",
data: [56000, 63000, 74000, 91000, 117000, 138000]
}, {
name: "Unique visitors",
data: [52000, 34000, 23000, 48000, 67000, 83000]
}],
valueAxis: {
max: 140000,
line: {
visible: false
},
minorGridLines: {
visible: true
},
labels: {
rotation: "auto"
}
},
categoryAxis: {
categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
majorGridLines: {
visible: false
}
},
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
});
}
当我这样做时,出现以下错误,这似乎表明 ChartOptions 应该是一个数组:
"Error 70 Argument of type '{ title: { text: string; }; legend: {
visible: boolean; }; seriesDefaults: { type: string; }; ser...' is not
assignable to parameter of type 'ChartOptions'. Types of property
'categoryAxis' are incompatible.
Type '{ [x: number]: undefined; categories: string[]; majorGridLines: { visible: boolean; }; }' is not assignable to type
'ChartCategoryAxisItem[]'.
Property 'length' is missing in type '{ [x: number]: undefined; categories: string[]; majorGridLines: { visible: boolean; }; }'."
如果我如下所示修改 createChart 函数,错误就会消失,但图表不会呈现:
function createChart() {
$("#chart").kendoChart([{ //Notice opening array bracket
title: {
text: "Site Visitors Stats \n /thousands/"
},
legend: {
visible: false
},
seriesDefaults: {
type: "bar"
},
series: [{
name: "Total Visits",
data: [56000, 63000, 74000, 91000, 117000, 138000]
}, {
name: "Unique visitors",
data: [52000, 34000, 23000, 48000, 67000, 83000]
}],
valueAxis: {
max: 140000,
line: {
visible: false
},
minorGridLines: {
visible: true
},
labels: {
rotation: "auto"
}
},
categoryAxis: {
categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
majorGridLines: {
visible: false
}
},
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
}]); // And closing array
}
还有其他人遇到过这个问题吗?在我看来是定义文件中的错误?
我已经为此类型定义创建了一个补丁,它允许您使用的确切代码。
它太大了,无法放在 Stack Overflow 上,所以补丁在这里:https://github.com/Steve-Fenton/DefinitelyTyped/blob/patch-1/kendo-ui/kendo-ui.d.ts
如果您的代码与此定义一起工作,我可以向 Definitely Typed 项目发送拉取请求以更新它(因此它将作为 NuGet 包等提供)。
我能够通过将 valueAxis 和 categoryAxis 值定义为数组来解决问题,如下所示:
function createChart() {
$("#chart").kendoChart({
title: {
text: "Site Visitors Stats \n /thousands/"
},
legend: {
visible: false
},
seriesDefaults: {
type: "bar"
},
series: [{
name: "Total Visits",
data: [56000, 63000, 74000, 91000, 117000, 138000]
}, {
name: "Unique visitors",
data: [52000, 34000, 23000, 48000, 67000, 83000]
}],
valueAxis: [{
max: 140000,
line: {
visible: false
},
minorGridLines: {
visible: true
},
labels: {
rotation: "auto"
}
}],
categoryAxis: [{
categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
majorGridLines: {
visible: false
}
}],
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
});
}
我正在使用下面显示的语法(取自 http://demos.telerik.com/kendo-ui/bar-charts/index)在 TypeScript 文件中创建一个 Kendo 图表:
function createChart() {
$("#chart").kendoChart({
title: {
text: "Site Visitors Stats \n /thousands/"
},
legend: {
visible: false
},
seriesDefaults: {
type: "bar"
},
series: [{
name: "Total Visits",
data: [56000, 63000, 74000, 91000, 117000, 138000]
}, {
name: "Unique visitors",
data: [52000, 34000, 23000, 48000, 67000, 83000]
}],
valueAxis: {
max: 140000,
line: {
visible: false
},
minorGridLines: {
visible: true
},
labels: {
rotation: "auto"
}
},
categoryAxis: {
categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
majorGridLines: {
visible: false
}
},
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
});
}
当我这样做时,出现以下错误,这似乎表明 ChartOptions 应该是一个数组:
"Error 70 Argument of type '{ title: { text: string; }; legend: { visible: boolean; }; seriesDefaults: { type: string; }; ser...' is not assignable to parameter of type 'ChartOptions'. Types of property 'categoryAxis' are incompatible. Type '{ [x: number]: undefined; categories: string[]; majorGridLines: { visible: boolean; }; }' is not assignable to type 'ChartCategoryAxisItem[]'. Property 'length' is missing in type '{ [x: number]: undefined; categories: string[]; majorGridLines: { visible: boolean; }; }'."
如果我如下所示修改 createChart 函数,错误就会消失,但图表不会呈现:
function createChart() {
$("#chart").kendoChart([{ //Notice opening array bracket
title: {
text: "Site Visitors Stats \n /thousands/"
},
legend: {
visible: false
},
seriesDefaults: {
type: "bar"
},
series: [{
name: "Total Visits",
data: [56000, 63000, 74000, 91000, 117000, 138000]
}, {
name: "Unique visitors",
data: [52000, 34000, 23000, 48000, 67000, 83000]
}],
valueAxis: {
max: 140000,
line: {
visible: false
},
minorGridLines: {
visible: true
},
labels: {
rotation: "auto"
}
},
categoryAxis: {
categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
majorGridLines: {
visible: false
}
},
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
}]); // And closing array
}
还有其他人遇到过这个问题吗?在我看来是定义文件中的错误?
我已经为此类型定义创建了一个补丁,它允许您使用的确切代码。
它太大了,无法放在 Stack Overflow 上,所以补丁在这里:https://github.com/Steve-Fenton/DefinitelyTyped/blob/patch-1/kendo-ui/kendo-ui.d.ts
如果您的代码与此定义一起工作,我可以向 Definitely Typed 项目发送拉取请求以更新它(因此它将作为 NuGet 包等提供)。
我能够通过将 valueAxis 和 categoryAxis 值定义为数组来解决问题,如下所示:
function createChart() {
$("#chart").kendoChart({
title: {
text: "Site Visitors Stats \n /thousands/"
},
legend: {
visible: false
},
seriesDefaults: {
type: "bar"
},
series: [{
name: "Total Visits",
data: [56000, 63000, 74000, 91000, 117000, 138000]
}, {
name: "Unique visitors",
data: [52000, 34000, 23000, 48000, 67000, 83000]
}],
valueAxis: [{
max: 140000,
line: {
visible: false
},
minorGridLines: {
visible: true
},
labels: {
rotation: "auto"
}
}],
categoryAxis: [{
categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
majorGridLines: {
visible: false
}
}],
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
});
}