有人能帮助我吗

我有2个文件main.ts和hi.ts

提示:

export const hello = "dd";

main.ts:
import { hello } from "./hi";
...
class A {
    public sayHello() {
        console.log("hello=" + hello);
    }
    ...
}

我有异常(exception):



我如何从A类看到此const变量?可能吗?

最佳答案

我的答案是关于TypeScript 2+的。

// 1.ts
export const AdminUser = { ... }

// index.ts
import * as users from './docs/users/admin';
var adminUser = users.AdminUser;
您的代码和我的代码之间唯一的区别是import语句中的*运算符。

09-25 18:28
查看更多