1

Using Typescript with Telerik's Kendo UI, I am at a bit of an impasse when it comes to how to properly define objects with a type of a widget.

For instance, if I want to declare a kendoEditor, I normally do the following...

var elements = {
   description: {}
};

elements.description = $('#description').kendoEditor({
   // options
}).data("kendoEditor");

elements.description.refresh(); // this is a function of kendo editor.

This works fine in normal javascript, but in typescript I am told that elements.description is not a type of kendo.ui.Editor. So I try to do it that way ...

var elements = { description: kendo.ui.Editor = null };

elements.description = $('#description').kendoEditor({ // options }).data("kendoEditor");

This works fine in the compiler, but at run time it says that it cannot assign it to null. But if I do not put = null, then it will not compile.

Can anyone express to me the correct way to do this? Additionally, any does not seem to be accepted either.

1 Answer 1

2

You can use a type assertion :

var elements = { 
    description: {} as kendo.ui.Editor
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.