javascript - 在 Typescript 中导出和导入模块
问题描述
我正在尝试导出一个简单的类,如下所示:
functions.ts
export class components{
private m_name:string;
private m_level:string;
constructor(name:string,level:string){
this.m_name=name;
this.m_level=level;
}
}
应用程序.ts
import {components} from './functions';
let c1 = new components("Tushar","Admin");
我包括被转译成 index.html 的 js 文件(app.js),如果它正在工作,可以在控制台上查看它。 索引.html
<!DOCTYPE html>
<html>
<head>
<title>
Feedback
</title>
</head>
<body>
<script src= "app.js"></script>
</body>
</html>
这是tsconfig.json文件:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
我收到一条错误消息:
未捕获的 ReferenceError:未在 app.js:2 中定义导出
我不明白为什么它不起作用。我尝试将目标更改为 es6 但没有帮助。虽然这在repl.it上运行良好
解决方案
推荐阅读
- django - 如何在 django 中获取外键关系数组
- java - Spring boot如何在内部处理这里的http请求?
- android - Fragment 接口/侦听器适用于 Activity,但不适用于另一个 Fragment
- reactjs - 做一个通用的函数来存储本地存储数据
- hadoop - 如何在已经创建的hadoop目录中创建一个子文件夹
- python - KMeans 聚类不平衡数据
- python - Pytest:设置 testclient 和 DB
- angular-material - 更改 matInput 的禁用属性值
- c# - 没有预定义大小的数组
- android - Rxjava2:Single 和 CompositeDisposable 的用法