![](/img/trans.png)
[英]How to roughly import .js libraries without type declaration in typescript?
[英]How to import in Typescript without module declaration
我有一堆自動生成的模塊,我需要從我的打字稿文件中引用。
例如
import test = require('../templates/test')
我正在使用ES5輸出生成CommonJS模塊。 所以我不能使用amd-dependency
(因為它僅適用於amd模塊)。 而且我也無法手動聲明模塊,因為1.它是自動生成的,2。它有一個相對路徑。
Typescript 1.6當前顯示錯誤,說“無法找到模塊”。 如何使它抑制此錯誤並導入?
如何使其抑制此錯誤並導入
如果您確定require
語句有效並且想要關閉導入的任何類型檢查 ,則可以使用node.d.ts
並執行:
var test = require('../templates/test')
即。 只需使用var
而不是import
。
如果要使用TypeScript導入(只是ES6導入),可以使用:
import * as test from '../templates/test';
然后像這樣調用你的API:
let foo = test.MY_API;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.