Typescript |声明变量类型的正确方法?
将Typescript与Telerik的Typescript |声明变量类型的正确方法?,typescript,Typescript,将Typescript与Telerik的剑道UI结合使用,在如何使用一种小部件正确定义对象方面,我遇到了一点僵局 例如,如果我想声明一个kendoEditor,我通常会执行以下操作 var elements = { description: {} }; elements.description = $('#description').kendoEditor({ // options }).data("kendoEditor"); elements.description.refr
剑道UI
结合使用,在如何使用一种小部件正确定义对象方面,我遇到了一点僵局
例如,如果我想声明一个kendoEditor
,我通常会执行以下操作
var elements = {
description: {}
};
elements.description = $('#description').kendoEditor({
// options
}).data("kendoEditor");
elements.description.refresh(); // this is a function of kendo editor.
这在普通的javascript中运行良好,但在typescript中,我被告知elements.description
不是kendo.ui.Editor
的类型。所以我试着这样做
变量元素={
描述:kendo.ui.Editor=null
};
elements.description=$('#description').kendoEditor({
//选择权
}).数据(“kendoEditor”)
这在编译器中可以正常工作,但在运行时它表示不能将其分配给null
。但是如果我不把=null
,那么它就不会编译
有人能告诉我做这件事的正确方法吗?此外,
任何
似乎也不被接受。您可以使用类型断言:
var elements = {
description: {} as kendo.ui.Editor
};