How can I extend and override an existing interface in TypeScript?
- 内容介绍
- 文章标签
- 相关推荐
本文共计129个文字,预计阅读时间需要1分钟。
示例:你有一个对象`A`,想扩展它并修改某些属性;然后创建一个新的接口`B`:例如,你有一个对象`A`,想扩展它并修改一些属性;然后创建一个新的接口`B`:export interface B extends Omit
Forexample,youhaveanobject`A`,youwanttoextenditandmodifysomeprop;thencreateanewinterfaceB:For example, you have an object `A`, you want to extend it and modify some prop; then create a new interface B:
export interface B extends Omit'x' | 'y'> { x: string; // override x y: number; // override y newProp?: string; // add new prop}
本文共计129个文字,预计阅读时间需要1分钟。
示例:你有一个对象`A`,想扩展它并修改某些属性;然后创建一个新的接口`B`:例如,你有一个对象`A`,想扩展它并修改一些属性;然后创建一个新的接口`B`:export interface B extends Omit
Forexample,youhaveanobject`A`,youwanttoextenditandmodifysomeprop;thencreateanewinterfaceB:For example, you have an object `A`, you want to extend it and modify some prop; then create a new interface B:
export interface B extends Omit'x' | 'y'> { x: string; // override x y: number; // override y newProp?: string; // add new prop}

