【问题标题】:material ui wrapper export interface casting any type in typescript (react)材料 ui 包装器导出接口在打字稿中铸造任何类型(反应)
【发布时间】:2020-02-10 06:08:13
【问题描述】:

我在 typescript 中使用 react。

我遇到了导出问题。我正在制作一个包含Material-ui 的界面。

例如,

Wrapping.tsx

import { default as Component, ComponentProps as MProps
}from '@material-ui/core/SomeComponent;

export interface MyPorps extends MProps {}
export default MyComponent: React.FC<MyPorps> = props => {
   some of render code
}

index.ts

import MyComponent from './wrapping'
import MyProps from './wrapping'
export default MyComponent;
export MyProps;

Usage.tsx

import MyComponent, { MyProps }from '@wrapping;
// waring: 'MyProps' has declared, but not use.

export default Myusage: React.FC<MyPorps> = props => {
    let data: MyProps = { 
       // MyProps has got error MyProps is any type
       // error code: 'MyProps ' refers to a value, but is being used as a type here.ts(2749)
    }
}

我不知道为什么MyProps 识别any 类型 MyPropslet dataimport { MyProps } 都不同

我的代码有问题吗?

【问题讨论】:

    标签: typescript import export material-ui


    【解决方案1】:

    我找到了解决方案。哈哈抱歉迟到了

    答案是

    import MyComponent from './wrapping'
    export default MyComponent;
    export * from './MyProps';
    

    export * from './MyProps' 是默认导出与其他导出内容的好方法

    【讨论】:

      猜你喜欢
      • 2020-12-20
      • 1970-01-01
      • 2018-11-17
      • 2022-12-30
      • 1970-01-01
      • 2020-11-30
      • 2023-03-08
      • 2021-02-05
      • 2021-10-18
      相关资源
      最近更新 更多