Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dojo 如何使用两个typescript 0.9.5接口,这两个接口都描述了;获得;功能?_Dojo_Typescript - Fatal编程技术网

Dojo 如何使用两个typescript 0.9.5接口,这两个接口都描述了;获得;功能?

Dojo 如何使用两个typescript 0.9.5接口,这两个接口都描述了;获得;功能?,dojo,typescript,Dojo,Typescript,我举了一个似乎有效的typescript示例(操场链接和内联): 我得到一个错误指示,在这两个接口中,属性“get”的类型不相同。(1) 我看不出这有什么关系,我不知道该如何解决这个问题 具体来说,我的界面如下所示: interface IGotoPane extends dijit._WidgetBase, dijit._TemplatedMixin, dijit._WidgetsInTemplateMixin { inputCoordinates: dijit._Widget; }

我举了一个似乎有效的typescript示例(操场链接和内联):

我得到一个错误指示,在这两个接口中,属性“get”的类型不相同。(1) 我看不出这有什么关系,我不知道该如何解决这个问题

具体来说,我的界面如下所示:

interface IGotoPane extends dijit._WidgetBase, dijit._TemplatedMixin, dijit._WidgetsInTemplateMixin {
    inputCoordinates: dijit._Widget;
}
我发现可以通过重新声明几个方法来消除编译器错误:

interface I3 extends I1, I2 {
        get(name: string): any;     
}
或者在我的具体问题上

interface IGotoPane extends dijit._WidgetBase, dijit._TemplatedMixin, dijit._WidgetsInTemplateMixin {
    inputCoordinates: dijit._Widget;
    get(name: string): any;
    set(name: string, value: any, raiseChangeEvent?: boolean): void;
    set(values: Dojo.PropertiesMap): void;
    watch(prop: string, callback: Dojo.WatchCallback<any>): Dojo.WatchHandle;
}
接口IGotoPane扩展dijit.\u WidgetBase,dijit.\u TemplatedMixin,dijit.\u WidgetsInTemplateMixin{
输入坐标:dijit.\u小部件;
get(name:string):任意;
set(名称:string,值:any,raiseChangeEvent?:boolean):void;
set(值:Dojo.PropertiesMap):void;
watch(prop:string,callback:Dojo.WatchCallback):Dojo.WatchHandle;
}

为什么有必要这样做?

关于属性需要相同的错误是一种常识--
I3的类型是什么?TypeScript中没有任何“合并”函数类型的概念,因此不清楚这到底意味着什么

您可以对简单的案例进行推理,但对于非平凡的案例,这种推理很快就会变得非常混乱,例如:

interface I1 {
    foo(a: string, b: "y"): number;
    foo(a: string, b: string): any;
}

interface I2 {
    foo(a: "x", b: string): boolean;
    foo(a: string, b: string): any;
}

interface I3 extends I1, I2 {
}

var x: I3;
var y = x.foo('x', 'y'); // y: number? boolean? any?

I3
中显式声明
get
的修复方法是正确的。如果在这种情况下适用,您可以复制常量专用签名。

谢谢。您的示例是一个很好的示例,我可以看到这种情况下的模糊性,但在“get”的情况下,显然应该优先使用专门的“get”。但是没有优先级,因此I1.get2和I2.get1变得不明确?我并没有完全理解编译器的问题,但也许这就是你所说的能够对简单的情况进行推理的意思。不是说我的直觉与你的问题无关,而是为了回答你的问题,我假设I3将采用以下形式:{get(name:“templatePath”):string;get(name:“baseClass”):string;get(name:string):any;}因此,在您的示例中,我假设返回类型是一个数字(“y”beats“x”):接口I3{foo(a:string,b:y”):数字;foo(a:x,b:string):布尔;foo(a:string,b:string):any;}
interface I1 {
    foo(a: string, b: "y"): number;
    foo(a: string, b: string): any;
}

interface I2 {
    foo(a: "x", b: string): boolean;
    foo(a: string, b: string): any;
}

interface I3 extends I1, I2 {
}

var x: I3;
var y = x.foo('x', 'y'); // y: number? boolean? any?