覆盖 Typescript d.ts 文件中定义的接口属性类型 [英] Overriding interface property type defined in Typescript d.ts file

查看:63
本文介绍了覆盖 Typescript d.ts 文件中定义的接口属性类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法改变打字稿中*.d.ts中定义的接口属性的类型?

Is there a way to change the type of interface property defined in a *.d.ts in typescript?

例如:x.d.ts 中的接口定义为

for example: An interface in x.d.ts is defined as

interface A {
  property: number;
}

我想在我写入的打字稿文件中更改它

I want to change it in the typescript files that I write to

interface A {
  property: Object;
}

甚至这也行

interface B extends A {
  property: Object;
}

这种方法行得通吗?当我在我的系统上尝试时它不起作用.只是想确认是否有可能?

Will this approach work? It didn't work when I tried on my system. Just want to confirm if it's even possible?

推荐答案

我使用的方法是先过滤字段,然后组合它们.

I use a method that first filters the fields and then combines them.

reference 从类型中排除属性

interface A {
    x: string
}

export type B = Omit<A, 'x'> & { x: number };

接口:

interface A {
    x: string
}

interface B extends Omit<A, 'x'> {
  x: number
}

这篇关于覆盖 Typescript d.ts 文件中定义的接口属性类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆