我的导入变得不确定,但是声明正在起作用,并且我从VSCode获得了智能提示,那么如何正确地键入声明我要从github导入的模块呢?
尝试了很多方法来声明,导出和命名d.ts,但没有任何效果。
// @types/index.d.ts
declare module "core" {
namespace Ioc {
interface IIoc {
bind(namespace: string, closure: Function): void;
singleton(namespace: string, closure: Function): void;
use(namespace: string): any;
}
interface IBindings {
[namespace: string]: {
closure: Function,
singleton: boolean,
cachedValue: Function | null
}
}
}
class Ioc implements Ioc.IIoc {
constructor();
bind(namespace: string, closure: Function): void;
singleton(namespace: string, closure: Function): void;
use(namespace: string): any;
}
}
// package.json
{
"name": "core",
"main": "./dist/index.js",
"types": "./dist/@types/index.d.ts"
}
// index.ts <- From another project using npm i <gitPath>
import { core } from 'core';
// Gets error cannot read property Ioc of undefined
console.log(new core.Ioc());
它提供了适当的智能感知,因此我希望正常运行代码并创建我的Ioc类,但是它告诉内核未定义,因此我认为其找不到模块或未使用文件的package.json位置编译。