Can';t在Typescript中导出常量
有人能帮我吗 我有两个文件main.ts和hi.ts 嗨,ts:Can';t在Typescript中导出常量,typescript,import,export,constants,Typescript,Import,Export,Constants,有人能帮我吗 我有两个文件main.ts和hi.ts 嗨,ts: export const hello = "dd"; main.ts: import { hello } from "./hi"; ... class A { public sayHello() { console.log("hello=" + hello); } ... } 我有例外: 未捕获引用错误:未定义hello(…) 如何从类A中查看此常量变量?可能吗?我的答案是关于TypeS
export const hello = "dd";
main.ts:
import { hello } from "./hi";
...
class A {
public sayHello() {
console.log("hello=" + hello);
}
...
}
我有例外:
未捕获引用错误:未定义hello(…)
如何从类A中查看此常量变量?可能吗?我的答案是关于TypeScript 2+
// 1.ts
export const AdminUser = { ... }
// index.ts
import * as users from './docs/users/admin';
var adminUser = users.AdminUser;
您的代码和我的代码之间的唯一区别是import语句中的
*
运算符。请参见此问题:我确实导出const hello=“dd”;就像在你的链接中一样,但它在Node.js或浏览器中不工作?在浏览器中(chrome和firefox相同)