使用自定义 JSX pragma 时是否可以允许扩展 DOM 元素属性?
类似于情感和样式组件如何css
在其 jsx 编译指示中使用道具和管理逻辑。我也想做同样的事情,但是可以通过泛型类型配置属性?
因此,例如:
// @jsx jsx
import { jsx } from 'my-lib';
...
<button<{ primary: boolean }> css={styles} primary={primary}>
Hello world
</button>
我当前的类型定义如下所示:
interface CustomAttributes {
css?: CSSProperties;
}
declare module 'react' {
interface DOMAttributes extends CustomAttributes {}
}
declare global {
namespace JSX {
interface IntrinsicAttributes extends CustomAttributes {}
}
}
我天真的解决方案看起来像这样:
interface CustomAttributes {
css?: CSSProperties;
}
declare module 'react' {
interface DOMAttributes<DynamicProps> extends CustomAttributes, DynamicProps {}
}
declare global {
namespace JSX {
interface IntrinsicAttributes<DynamicProps> extends CustomAttributes, DynamicProps {}
}
}