Typescript gives, “Could not find a declaration file for module 'xmlhttprequest'.”

前端 未结 2 1539
礼貌的吻别
礼貌的吻别 2021-01-28 10:32

Using,

import { XMLHttpRequest } from \'xmlhttprequest\';

On Node I get the following error when I compile with tsc

相关标签:
2条回答
  • 2021-01-28 10:51

    Can you try to do npm install @types/xmlhttprequest --save in your command line.

    If it gives you error, then it means that xmlhttprequest library does not support TypeScript.

    0 讨论(0)
  • 2021-01-28 11:07

    That means that the library does not contain type definitions and nobody from the DefinitelyTyped project wrote them. So you can't have the compiler do any typechecking. You can still use the library either

    import * as xhr from 'xmlhttprequest'
    

    Or, depending on version of your compiler

    const xhr = require('xmlhttprequest')
    
    0 讨论(0)
提交回复
热议问题