无法在 Typescript 中导出常量

2024-01-11

有人能帮助我吗

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

hi.ts:

export const hello = "dd";

main.ts:

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

我有例外:

未捕获的引用错误:hello 未定义(...)

我怎样才能从A类中看到这个const变量?是否可以?


我的答案是指 TypeScript 2+。

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

// index.ts
import * as users from './docs/users/admin';
var adminUser = users.AdminUser;

你的代码和我的代码之间的唯一区别是*导入语句中的运算符。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在 Typescript 中导出常量 的相关文章

随机推荐