我将IDB与typescript一起使用,并尝试定义EventTarget,以便从中获取结果和错误。
通常对于操作,我们会将错误视为event.target.error
,结果为event.target.result
。
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);
};
我试过以下
interface EventTarget {
error?: any;
result: any;
}
会产生很多无关的错误。我使用最新的开发分支(de583a588d7be350ac5108118a807715fcf83519)。
我能做些什么
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(或在事件中)中看到目标,
interface SVGAElement extends SVGElement, SVGStylable, SVGTransformable, SVGLangSpace, SVGTests, SVGExternalResourcesRequired, SVGURIReference {
target: SVGAnimatedString;
}
我尝试用EventTarget
和error
扩展result
。
我不确定EventTarget
的这些循环扩展是如何工作的。我是新手稿。
interface IDBRequest extends EventTarget {
onsuccess: (ev: Event) => any;
onerror: (ev: ErrorEvent) => any;
interface Event {
....
target: EventTarget;
eventPhase: number;
....
答案 0 :(得分:1)
result
和SVGElement
的{{1}}类型必须完全相同。
您将收到此错误的一种情况是,如果一个接口接口实现另一个接口,并且子接口不使用与父接口相同的类型:
SVGFilterPrimitiveStandardAttributes