gpt4 book ai didi

javascript - typescript 模块没有导出成员 - react

转载 作者:数据小太阳 更新时间:2023-10-29 04:01:24 24 4
gpt4 key购买 nike

我正在开发一个 React、redux Typescript 应用程序。我有一种奇怪的情况,在进行一些更改后,其中一个模块已停止导出其成员。

文件夹结构是:

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

“组件”文件夹包含 .tsx 文件,而包装 .ts 文件位于“容器”文件夹中。

模块 NodeList.tsx 如下所示:

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>
)

包装容器 NodeListContainer 是:

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)

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

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

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

最佳答案

如果您更正错字,您的代码应该可以正常工作。

代替

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

你应该写:

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

关于javascript - typescript 模块没有导出成员 - react ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37146858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com