0

在我的 Asp.Net MVC 网页中,我使用的是 X-Editable jQuery 插件。而且我有一个扩展abstractinput的自定义复杂表单。

在普通的 javascript 中,它的声明如下所示

$.fn.editableutils.inherit(MyCustomForm, $.fn.editabletypes.abstractinput);

但我需要在 Typescript (v0.9.5) 类中使用它,并且我正在以这样一种天真的方式进行操作

export class MyCustomForm extends $.fn.editabletypes.abstractinput { ... }

它正在工作,至少它可以编译并转换为 javascript,但有错误。开发(调试)跳过这些错误是可以的,但是当我发布项目时,所有这些错误都会破坏发布过程。

如何正确扩展这种结构?

4

1 回答 1

0

$.fn.editabletypes.abstractinput is a function but is being used as a type.

If you want to extend Javascript objects in TypeScript your can try this solution: How to extend native JavaScript array in TypeScript


If the implementation of $.fn.editabletypes.abstractinput was in TypeScript, you would have to define interfaces:

interface JQueryFn //*
{
    editabletypes?: XEditableTypes;
}

interface XEditableTypes
{
    abstractinput: XEditableAbstractInput;
}

class XEditableAbstractInput { }

class MyCustomForm extends XEditableAbstractInput
{

}

However $.fn is currently defined as any, so you won't get reliable intellisense.

A Javascript object is not a type. TypeScript types only exist in TypeScript. Don't mix concepts.

于 2013-12-22T18:47:11.777 回答