【问题标题】:How to convert interfaces from typescript to javascript?如何将接口从 typescript 转换为 javascript?
【发布时间】:2021-03-14 03:56:47
【问题描述】:

我有想要转换为 Javascript 的打字稿代码:

interface Props {
  children?: ReactElement | Array<ReactElement>;
}

const Trail: React.FC<Props> = ({ children, ...props }) => {

由于没有接口,我如何将其转换为 javascript 中的类似内容?

【问题讨论】:

  • 你能准确解释一下你的用例吗? TypeScript 编译为 JavaScript;如果你想将 TypeScript 转换为 JavaScript,只需编译它。这将删除接口和静态类型系统的任何其他痕迹。这不是你想要的,那么你应该详细说明你期望看到的不同。
  • 您只需删除整个interface 和类型注释: React.FC&lt;Props&gt;。你仍然可以用同样的方式解构你的 props,但是你会丢失所有关于它们类型的信息,因为那只存在于 typescript 中。

标签: javascript typescript interface react-props


【解决方案1】:

你删除它:

const Trail = ({ children, ...props }) => {

看看 Typescript 生成了什么。

【讨论】:

    猜你喜欢
    • 2017-04-25
    • 1970-01-01
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 2021-01-17
    • 2021-12-24
    • 2016-11-18
    • 2017-10-09
    相关资源
    最近更新 更多