未定义TypeScript导出

未定义TypeScript导出

本文介绍了未定义TypeScript导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用导出和导入,但是我收到错误消息

I'm trying to use export and import but it not working I get an error

这是我的代码HTML:

Here is my code HTML :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    @RenderBody()

    <script src="~/scripts/user.js"></script>
    <script src="~/scripts/main.js"></script>
</body>
</html>

User.ts:

export class User {
    firstName: string;
    lastName: string;
}

main.ts

import { User } from "./user";

这也是异常的屏幕截图:

Here is also screenshot of exception :

推荐答案

您有几个选择:

选项1:使用模块加载程序,例如 Webpack , Browserify等.

Option 1: Use a module loader like Webpack, Browserify, etc.

选项2:如果只想将*.ts编译为*.js而没有任何模块导入或导出,请在tsconfig.json中将compilerOptions.module设置为"none".请注意,将compilerOptions.module设置为无"时,将无法导出/导入模块.

Option 2: If you just want to compile *.ts to *.js without any module imports or exports, set compilerOptions.module to "none" in your tsconfig.json. Note that you won't be able to export/import modules when you set compilerOptions.module to "none".

这篇关于未定义TypeScript导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 20:28