[英]How to call an exported typescript function from within javascript
I have a typescript file with imports eg:我有一个带有导入的打字稿文件,例如:
util.ts file util.ts 文件
import { protractor } from 'protractor'
export const waitForFile = async () => {
protractor.promise....
return await ''
}
Now helper.js file现在 helper.js 文件
const getUtilFunction = (func) => {
const { register } = require('ts-node');
const { compilerOptions } = require('./tsconfig.json');
register({ compilerOptions });
const result = require('./utils.ts');
return result[func];
};
const waitTillReportGenerated = async () => {
const waitForFileToDownload = getUtilFunction('waitForFileToDownload');
const file = await waitForFileToDownload('./result/result.js', 60000);
console.log(file);
}
However when we call the helper.js function it throws error that protractor is undefined.然而,当我们调用 helper.js 函数时,它会抛出量角器未定义的错误。 Can someone please help me with this?有人可以帮我吗?
您需要将.ts
文件转换为.js
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.