流/打字稿从字符串验证HTML元素类型

时间:2019-11-01 16:46:10

标签: html reactjs typescript flowtype

我正在寻找一种使用Flow / React / ReactDOM的标准方法,以验证字符串是有效的html元素类型。

我在那里使用率达99%

const generateComponent = (ComponentString: $Keys<$JSXIntrinsics>, styleObject) => {
  return <ComponentString foo="bar" />
}

const ValidComponent = generateComponent('div');
const ShouldThrowErrorComponent = generateComponent('divv');

但是流程的“ catchall”字符串使任何字符串成为有效的html元素。

必须使用打字稿/流来实现这一点,对吧?
我的目标是避免编写自己的自定义列表,例如this
而是使用已建立的库,例如this

但没有行271 [string]: ReactDOM$HTMLElementJSXIntrinsic,破坏了显式检查

0 个答案:

没有答案