[英]Typescript 2: Custom Type definition in node_modules
Let's say I publish a custom library called my-library
. 假设我发布了一个名为
my-library
的自定义my-library
。 This library will be of the structure 该库将具有以下结构
node_modules/
my-library/
lib/
index.js
src/
...
typings/
index.d.ts
package.json
Say now I export default something called Application
from the index.js, so you use it by import Application from 'my-library';
现在说我从index.js导出默认的名为
Application
东西,因此您可以通过import Application from 'my-library';
使用它import Application from 'my-library';
Now, in my index.d.ts
I want to declare its typing: 现在,在我的
index.d.ts
我想声明其类型:
export = Application;
export as namespace Application;
declare namespace Application {
function foo(arg1: string): object;
}
I know expect this to return an error but it does not: 我知道这会返回错误,但是不会:
import Application from 'my-library';
Application.foo(123)[0].blahblah;
Not only is the argument wrong, but so is the use of the return value. 该参数不仅错误,而且返回值的使用也错误。 I don't know how I am supposed to add my type definitions so that the above works.
我不知道应该如何添加我的类型定义,以便上面的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.