Задать вопрос
@Makusimu

Использование библиотеки имеющей typescript d.ts?

Изучаю typescript.
Столкнулся с проблемой подключения бибилотеки axios.

Файл main.ts:
/// <reference path="../node_modules/axios/index.d.ts" />
//import axios from 'axios';

export function ok_lets_go()
{
  axios.get('https://ya.ru')
  .then((response) => {
    console.log(response.data);
    console.log(response.status);
  });
}


Если в коде раскоментировать строку импорта
//import axios from 'axios';
То все прекрасно компилируется без ошибок. Но тогда в Js код попадает эта самая строка импорта и на нее ругается браузер (Edge на основе Chromium).

Если оставить строку
/// <reference path="../node_modules/axios/index.d.ts" />

тогда возникают ошибки копиляции

error TS2304: Cannot find name 'axios'.

error TS7006: Parameter 'response' implicitly has an 'any' type.


Файл axios/index.d.ts находится, пробовал задавать заведомо неверное имя - возникает сообщение об ошибке что файл не найден.

Файл index.html:
<!DOCTYPE html>
<meta charset="utf-8">
<html>
  <head>
    <title>eXtodo</title>
    <meta name="google" content="notranslate">
    <meta http-equiv="Content-Type" content="text/html; Charset=utf-8">
    <script type="text/javascript" src="./build/axios.js"></script>
  </head>

  <body>
    <div id='app'></div>

    <script type="module">
      import {ok_lets_go} from './build/main.js';
      ok_lets_go();
    </script>
  </body>
</html>


Файл tsconfig.json
{
  "compilerOptions": {
    "target": "ES6",
    "module": "es6",
    "sourceMap": true,
    "outDir": "./build",
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "types": ["node"]
  },
  "compileOnSave": true,
  "include": ["./src"],
}
  • Вопрос задан
  • 169 просмотров
Подписаться 1 Простой Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы