首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IDB: EventTarget的类型标定义

IDB: EventTarget的类型标定义
EN

Stack Overflow用户
提问于 2014-03-22 00:12:34
回答 1查看 1.5K关注 0票数 1

我使用IDB和类型记录,并试图定义EventTarget,这样我就可以从它得到结果和错误。

通常,对于操作,一个获得错误作为event.target.error和结果event.target.result

代码语言:javascript
复制
var request = objectStore.add(data);
        request.onerror = function(event) {
          console.log(event.target.error)
        }
        request.onsuccess = function(event) {
          callback(event.target.error,event.target.result);
        };

我试过像下面这样

代码语言:javascript
复制
interface EventTarget {
    error?: any;
    result: any;
}

这就产生了很多无关的错误。我使用最新的开发分支(de583a588d7be350ac5108118a807715fcf83519)。

我能做些什么

代码语言:javascript
复制
Using tsc v1.0.0
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11030,11): error TS2189: Interface 'SVGFEFloodElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11100,11): error TS2189: Interface 'SVGFETileElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11108,11): error TS2189: Interface 'SVGFEBlendElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11139,11): error TS2189: Interface 'SVGFEMergeElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11262,11): error TS2189: Interface 'SVGFEGaussianBlurElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11339,11): error TS2189: Interface 'SVGFESpecularLightingElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11442,11): error TS2189: Interface 'SVGFEMorphologyElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11473,11): error TS2189: Interface 'SVGFEDisplacementMapElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11614,11): error TS2189: Interface 'SVGFEConvolveMatrixElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11664,11): error TS2189: Interface 'SVGFETurbulenceElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11709,11): error TS2189: Interface 'SVGFEColorMatrixElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(11820,11): error TS2189: Interface 'SVGFEOffsetElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(12102,11): error TS2189: Interface 'SVGFEImageElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(12116,11): error TS2189: Interface 'SVGFECompositeElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(12206,11): error TS2189: Interface 'SVGFEComponentTransferElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
/usr/local/lib/node_modules/typescript/bin/lib.d.ts(12214,11): error TS2189: Interface 'SVGFEDiffuseLightingElement' cannot simultaneously extend types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes':
Named properties 'result' of types 'SVGElement' and 'SVGFilterPrimitiveStandardAttributes' are not identical.
>> Compilation failed

编辑:

我可以看到目标在SVGAElement中使用(或者在事件中),

代码语言:javascript
复制
interface SVGAElement extends SVGElement, SVGStylable, SVGTransformable, SVGLangSpace, SVGTests, SVGExternalResourcesRequired, SVGURIReference {
    target: SVGAnimatedString;
}

我尝试的是用errorresult扩展error

我不知道EventTarget的这些循环扩展是如何工作的。我对打字本还不熟悉。

代码语言:javascript
复制
interface IDBRequest extends EventTarget {
  onsuccess: (ev: Event) => any;
  onerror: (ev: ErrorEvent) => any;

interface Event {
   ....
    target: EventTarget;
    eventPhase: number;
   ....
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-22 05:37:29

result的类型必须与SVGElementSVGFilterPrimitiveStandardAttributes完全相同。

如果一个接口接口实现了另一个接口,而子接口没有使用与父接口相同的类型,就会出现此错误:

代码语言:javascript
复制
interface FooEvent{
    data: number;
}

interface BarEvent extends FooEvent{
    data: string;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22571707

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档