types - 如何声明 TypeScript 导入 * 类型?

如何在 TypeScript 中显式声明 import * as ... 中的类型?

我有这段代码:

import * as UnauthorizedInterface from './interfaces/InterfaceA'
import * as AuthorizedInterface from './interfaces/InterfaceB'

export class App extends React.Component<{children?: React.ReactChildren, authorized?: Boolean}, {}> {
public render() {
    return <Router>
        <Route component={Interface}>
            <Route path="/application" components={InterfaceA}
...

我得到了

ERROR in ./src/components/App.tsx
(16,24): error TS2322: Type 'typeof "~/src/interfaces/InterfaceA"'' is not assignable to type '{ [key: string]: string | ComponentClass<any> | StatelessComponent<any>; }'.
Index signature is missing in type 'typeof "~/src/interfaces/InterfaceA"'.

尽管它只是导出扩展 React.ComponentClass 的实体

最佳答案

import * as UnauthorizedInterface from './interfaces/InterfaceA'

我想你可能是想做 import {UnauthorizedInterface} from './interfaces/InterfaceA'。当然,如果您使用模块(这是您通过* as 获得的)作为一个类,您将得到您所得到的错误。

https://stackoverflow.com/questions/34141572/

相关文章:

xml - 将带有越南字符的数据导入 R

node.js - 如何在 mongodb 中插入嵌套对象?

mongodb - 如何运行 mongo-express(无需身份验证)?

git - 为什么 cherry-pick 告诉我所有线路都已更改?

java - 收听 RabbitMQ 队列并获取事件通知

php - Symfony 2 - 登录服务

javascript - 日期选择器 Bootstrap 中的工具提示错误

d3.js - d3 中的自定义比例

matrix - Spark RDD 到 Matrix

eclipse - 我可以在 Eclipse Indigo 3.7.2 中使用 Tomcat 8.0