在tsconfig.json中将jsx
设置为react
并将jsxFactory
设置为fn
时,
还有一些错误:
a.tsx
import fn from "./fn";
import delegate from "./delegate";
class A {
constructor(point: { x: number, y: number }){
console.log(x, y);
// ...
}
}
delegate(
<A target={document.getElementById("myId")} />
);
delegate.ts
export default function delegate({ type, props: { target } }){
target.onClick = (e) => {
new type(e.clickX, e.clickY);
};
};
错误:Type '{ target: HTMLElement; }' is not assignable to type '{ x: number;, y: number; }'
和Property 'target' does not exist on type '{ x: number; y: number; }'
我如何禁用道具检查? 不必关心代码的逻辑,因为,这只是一个例子。
答案 0 :(得分:1)
您可以将道具声明为any
,然后传播(...
)道具:
delegate(
<A {...({ target: document.getElementById("myId") } as any)} />
);
答案 1 :(得分:0)
代码如下:
jsx-namespace.d.ts
declare namespace JSX {
// ...
interface IntrinsicAttributes {
[attributeName: string]: any
}
// ...
}
typescript 3.4.5