如何将js-modules导入TypeScript文件? [英] How to import js-modules into TypeScript file?

查看:136
本文介绍了如何将js-modules导入TypeScript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含这样一个文件的Protractor项目:

I have a Protractor project which contain such a file:

var FriendCard = function (card) {
    var webElement = card;
    var menuButton;
    var serialNumber;

    this.getAsWebElement = function () {
        return webElement;
    };

    this.clickMenuButton = function () {
        menuButton.click();
    };

    this.setSerialNumber = function (numberOfElements) {
        serialNumber = numberOfElements + 1;
        menuButton = element(by.xpath('.//*[@id=\'mCSB_2_container\']/li[' + serialNumber + ']/ng-include/div/div[2]/i'));
    };

    this.deleteFriend = function () {
        element(by.css('[ng-click="deleteFriend(person);"]')).click();
        element(by.css('[ng-click="confirm()"]')).click();
    }
};
module.exports = FriendCard;

该文件的路径是


./ pages / FriendCard.js

./pages/FriendCard.js

我没有问题,使用导入到另一个文件require()方法:

I have no problems whith it's import to another file using require() method:

var FriendCard = require('./../pages/FriendCard');

所以,我决定将这个文件导入到TypeScript文件中:

So, I've decided to import this file to the TypeScript file just like that:

import {FriendCard} from './../pages/FriendCard'

我正在使用WebStorm,因此它告诉我,( TS2305 )它没有导出成员'FriendCard'。

I'm using WebStorm, so it tells me, that (TS2305) it has no exported member 'FriendCard'.

也许我必须以某种方式配置tsconfig.json文件,但我仍然不知道它是如何工作的。你可以帮帮我吗?

Maybe I have to configure tsconfig.json file somehow, but I still don't know how it works. Could you help me?

推荐答案

您可以按如下方式导入整个模块:

You can import the whole module as follows:

import * as FriendCard from './../pages/FriendCard';

有关详细信息,请参阅 modules 部分。

For more details please refer the modules section of Typescript official docs.

这篇关于如何将js-modules导入TypeScript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆