Typescript 模块没有导出成员 - 反应 [英] Typescript module has no exported members - react

查看:528
本文介绍了Typescript 模块没有导出成员 - 反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 react、redux Typescript 应用程序.我有一个奇怪的情况,经过一些更改后,其中一个模块停止导出其成员.

文件夹结构为:

src|---- 组件|---- 集装箱

components"文件夹包含 .tsx 文件,而包装 .ts 文件位于containers"文件夹中.

NodeList.tsx 模块如下:

import * as React from "react";export const NodeList = (props) =>(<div id="节点列表"><ul>{props.items.map((item, i) => (<li key={i} ><span id={"Item_"+i}>{item}</span>))}

)

包装容器 NodeListContainer 是:

import { connect } from "react-redux";从react-redux"导入{提供者};从../components/NodeList"导入 { Nodelist }const nodesAsArrayOfType = (state, nodeType: string) =>{console.log("寻找类型为"的节点,nodeType)让 a = state.data.model.nodes让 k = Object.keys(a);让 sub = k.filter((e) => {返回 a[e].nodeType == nodeType}).map((e) => a[e])console.log("得到节点", sub)返回子}const mapStateToProps = (状态) =>{var list = nodesAsArrayOfType(state, state.UIstate.focusNodeType).map((e) => {return JSON.stringify(e)})console.log("返回", list, list.length)返回 {项目:列表}}const mapDispatchToProps = (调度) =>{返回 {newTextValue: (e) =>{调度({类型:ON_CHANGE",文本:e.target.value})}}}导出 const NodeListContainer = 连接(mapStateToProps,mapDispatchToProps)(节点列表)

上面的NodeList的导入被标记为错误信息

 ./src/containers/NodeListContainer.ts 中的错误(4,10): 错误 TS2305: 模块 '"MyP​​roject/src/components/NodeList"' 没有导出成员 'Nodelist'.

谁能就这里可能发生的事情提供任何见解?

解决方案

如果你修正了你的错字,你的代码应该可以工作.

代替

import { Nodelist } from "../components/NodeList"

你应该写:

import { NodeList } from "../components/NodeList"//^ 大写 L

I am working on a react, redux Typescript application. I have a strange situation where after some changes one of the modules has stopped exporting its members.

The folder structure is:

src
|---- components
|---- containers

The 'components' folder has the .tsx files while the wrapping .ts files are in the 'containers' folder.

The module NodeList.tsx is listed below:

import * as React from "react";

export const NodeList = (props) => (
    <div id="NodeList">
        <ul>
        {props.items.map((item, i) => (
            <li key={i} >
                <span id={"Item_"+i}>{item}</span>
            </li>
            )
        )}
        </ul>
    </div>
    )

The wrapping container NodeListContainer is:

import { connect } from "react-redux";
import { Provider } from "react-redux";

import { Nodelist } from "../components/NodeList"

const nodesAsArrayOfType = (state, nodeType: string) => {
    console.log("Going for nodes of type ", nodeType)
    let a = state.data.model.nodes
    let k = Object.keys(a);
    let sub = k.filter((e) => {
                   return a[e].nodeType == nodeType
        }).map((e) => a[e])
    console.log("Got nodes ", sub)    
    return sub
}

const mapStateToProps = (state) => {
    var list = nodesAsArrayOfType(state, state.UIstate.focusNodeType).map((e) => {return JSON.stringify(e)})
    console.log("Returning ", list, list.length)
    return {
        items: list
    }
}

const mapDispatchToProps = (dispatch) => {
    return {
        newTextValue: (e) => {dispatch({type: "ON_CHANGE", text: e.target.value})}
    }
}

export const NodeListContainer = connect(
    mapStateToProps,
    mapDispatchToProps
    )(NodeList)

The import of NodeList above is being flagged with the error message

ERROR in ./src/containers/NodeListContainer.ts
(4,10): error TS2305: Module '"MyProject/src/components/NodeList"' has no exported member 'Nodelist'.

Can anyone provide any insight into what might have happened here?

解决方案

Your code should work if you fix your typo.

Instead of

import { Nodelist } from "../components/NodeList"

you should write :

import { NodeList } from "../components/NodeList"
//           ^ capital L

这篇关于Typescript 模块没有导出成员 - 反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆