简体   繁体   中英

How to call an exported typescript function from within javascript

I have a typescript file with imports eg:

util.ts file

import { protractor } from 'protractor'

export const waitForFile = async () => {
 protractor.promise....
 return await ''
}

Now helper.js file

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. Can someone please help me with this?

您需要将.ts文件转换为.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM