简体   繁体   English

命名空间在.d.ts文件中合并

[英]Namespace merge in .d.ts file

Another document(.d.ts)(try) 另一个文件(.d.ts)(尝试)

import Kvl from 'kvl';

declare namespace kvl {
    interface test1{

    }
}
//error

a total document(.d.ts) 总文件数(.d.ts)

declare class kvl {}

declare namespace kvl{
    interface Request {}
    interface Response {

    }
}
export as namespace kvl;
export default kvl;

Another document(.d.ts) 另一个文件(.d.ts)

import Kvl from 'kvl';

declare module "kvl" {

    namespace kvl {
        interface test1{

        }
    }
}

Project code 项目代码

import kvl from 'kvl';
const name: kvl.test1;

kvl.test1[error] kvl.test1 [错误]

I want to add a method to the namespace inside .d.ts, but my addition failed. 我想在.d.ts内的命名空间中添加一个方法,但是添加失败。

Found a solution 找到了解决方案

declare class kvl {

}

declare global{
    namespace kvl{
        interface Request {}
        interface Response {}
    }

}



export as namespace kvl;
export default kvl;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM