覆盖 Typescript d.ts 文件中定义的接口属性类型

编程入门 行业动态 更新时间:2024-10-27 22:20:06
本文介绍了覆盖 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 文件中定义的接口属性类型

本文发布于:2023-06-12 05:12:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/651943.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   接口   定义   类型   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!