我有两个文件comment.tsx和commentlist.tsx进口类+反应过来
comment.tsx看起来是这样的:
/// <reference path="./typings/react/react.d.ts" />
/// <reference path="./typings/react/react-dom.d.ts" />
/// <reference path="interfaces.d.ts" />
import * as React from "react";
import * as ReactDOM from "react-dom";
namespace W.T.F {
export class Comment extends React.Component<ICommentData, {}>{
constructor(props: ICommentData) {
super(props);
}
public render() {
return (
<div className="comment">
<h2 className="commentAuthor">{this.props.Author}</h2>
<span>{this.props.Text}</span>
</div>
);
}
}
}
和commentlist.tsx
/// <reference path="./typings/react/react.d.ts" />
/// <reference path="./typings/react/react-dom.d.ts" />
/// <reference path="comment.tsx" />
/// <reference path="interfaces.d.ts" />
import * as React from "react";
import * as ReactDOM from "react-dom";
import Comment = W.T.F.Comment;
namespace W.T.F {
export class CommentList extends React.Component<ICommentListData, {}>{
public render() {
var commentNodes = this.props.Data.map(function (comment: ICommentData) {
return (
<Comment Author={comment.Author} Text={comment.Text}>{comment.Text}</Comment>
);
});
return (
<div className="commentList">
{commentNodes}
</div>
);
}
};
}
编译这些文件所带来的误差
commentlist.tsx(8,24)TS2305模块“WT .F'没有导出成员'评论'。
我的来源有什么问题?
从其他文件导入其他反应类(包含在名称空间中)的最佳方法是什么?
现在你的两个文件都是“外部模块”。在“命名空间W.T.F”中移动导入语句。您可能需要将其更改为“声明命名空间...”。 – Louy
结帐**陷阱** https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Namespaces%20and%20Modules.md。如果你想使命名空间的工作,你必须导出它们afaik。 – FlorianTopf
hm ..我看到我必须删除外部模块中的命名空间,但是.tsx文件作为外部模块处理和.ts文件处理的原因是什么? – Henk