Как импортировать модуль NPM в TypeScript? - PullRequest
0 голосов
/ 22 сентября 2019

Как мы можем импортировать модули npm, такие как axios, в TypeScript с нуля?

Я использую только файл tsconfig.json с TypeScript.

Вот мой файл .ts.

import * as file2 from './file2'; 
alert(file2.x);


import * as axios from './node_modules/axios';
axios.get('http://webcode.me', undefined).then(resp => {

    alert(resp.data);
}).catch(err => alert(err));

Вот мой tsconfig.json файл:

{
  "compilerOptions": {
    "target": "es5",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
    "module": "amd"                    /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...