![](/img/trans.png)
[英]Creating a declaration file in TypeScript to use a JavaScript library
[英]How do I import a Javascript library into Typescript when the package has a declaration file
我正在嘗試使用callbag庫中的類型定義。 這個庫在它的 package.json 中聲明了它的類型定義文件。 它不會上傳到絕對類型。 當我嘗試導入庫時,出現錯誤:
Cannot find module 'callbag'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
這是我導入它的方式:
import type { Sink } from 'callbag';
這是我的tsconfig.json
:
{
"compilerOptions": {
"module": "es6",
"noEmitOnError": true,
"outDir": "./dist",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es5"
},
"include": ["./src/**/*"]
}
我還嘗試將"types": ["callbag"]
到 tsconfig.json,但沒有奏效。
我如何讓打字稿識別這個庫的類型?
正如評論中發布的那樣,我需要將"moduleResolution": "node"
到我的 tsconfig.json 中。 不知道為什么,因為我所做的一切都與 Node.js 無關。 但那是有效的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.