SanchelliosProg SanchelliosProg - 3 years ago 138
TypeScript Question

How to import js-modules into TypeScript file?

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;


Path to the file is


./pages/FriendCard.js


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

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


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

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


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

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

Answer Source

You can import the whole module as follows:

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download