gpt4 book ai didi

javascript - 如何将变量从 .ts 文件导入到 .js 文件

转载 作者:太空宇宙 更新时间:2023-11-04 00:05:15 26 4
gpt4 key购买 nike

对于我的项目,我需要导入 .ts 文件中声明的变量以在 .js 文件中使用。我无法将 js 文件更改为 ts 文件,因为其中写入了其他函数,这会受到影响。

我尝试了很多使用:

import AvailableBalances = require('./app.Processing');

import { AvailableBalances } from './app.Processing';

但没有任何帮助。下面是我在 .ts 文件中的代码。 'Comment' 是变量,例如我需要在 .js 文件中导入和使用。

describe('Login', function () {
it('Should able to login into the Webpage', function () {

browser.driver.manage().window().maximize();
browser.get('https://inside.pilot.theprincipal.net/rnqLiabilityManagement/');
var Comment = 'Login Successful';

最佳答案

您必须了解 .ts 是什么以及 JavaScript 模块如何工作:

.ts 文件是用 TypeScript 编写的文件,需要评估(和使用)TypeScript 运行时。

JavaScript 模块有点复杂,因为有很多东西需要理解。首先,并非所有运行时(JavaScript 评估器)都可以计算模块导入/导出。其次,如果您在 JavaScript 中设置了导入模块的所有内容,则需要注意它可能会错过导入 TypeScript 文件的某些内容。

您没有提供太多有关您的工具的信息。但如果您使用 Webpack,则必须添加“TypeScript 加载器”才能将 TypeScript 模块导入 JavaScript 模块。

如果您需要更多详细信息,请告诉我。

关于javascript - 如何将变量从 .ts 文件导入到 .js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52623933/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com