本文介绍了覆盖 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 文件中定义的接口属性类型
发布评论