首页 > 解决方案 > 打字稿:扩展/覆盖类类型定义

问题描述

我正在使用来自另一个外部库的外部库的类型。为一些类提供的类型还不够,我想知道如何扩展/覆盖它们。

打字库的module.d.ts

declare module '@library/module' {
    export class SomethingImportant {
        constructor(props?: any);
    }
}

我想像这样更新打字(来自我已经在我的代码中设置的打字文件):

declare module '@library/module' {
    export interface ImportantProps {
        name: string;
        age: number;
    }
    export class SomethingImportant {
        constructor(props?: ImportantProps);
    }
}

该接口按我的预期导出,但在我的代码的其他地方,类型的props类型没有强制执行。我可以做到new SomethingImportant({banana: true}),打字稿不会抱怨。

我正在尝试做的事情可能吗?

标签: typescripttypescript-typings

解决方案


推荐阅读