我有一个包含.ts
和.tsx
文件的项目,我试图从一个.ts
文件中导入一个.tsx
文件,代码如下:
src/index.ts
import WriteEditor from './write_editor';
src/write_editor.tsx
import Events from './events';
import Actions from './actions';
export default class WriteEditor extends React.Component { /*...*/ }
现在TypeScript告诉我:
所以我尝试了这个:错误:./src/index.ts 找不到模块:错误:无法解析'/Users/luke/Projekte/writejs/code/writejs/src'中的'./write_editor' @ ./src/index.ts 3:23-48 @ multi ./src/index.ts
src/index.ts
import WriteEditor from './write_editor.tsx';
现在我的IDE提示我不要写扩展名
tsx
,并且我在src/write_editor.tsx中遇到了错误,因为TypeScript无法从.tsx
文件中找到我的.ts
文件。
然后我去重命名导入,并添加了.ts
扩展名。import Events from './events.ts';
import Actions from './actions.ts';
现在我收到了很多错误提示,告诉我不要写扩展。
那么我们如何从 ts
导入 tsx
,反之亦然呢?
write_editor.jsx
和write_editor.tsx
。为什么会有一个.jsx
文件? - cartanttsx
。 - Lukas.ts
和.tsx
扩展名? - loganfsmyth