patternjavascriptCritical
Overriding interface property type defined in Typescript d.ts file
Viewed 0 times
propertytypescriptoverridinginterfacedefinedfiletype
Problem
Is there a way to change the type of interface property defined in a
for example:
An interface in
I want to change it in the typescript files that I write to
or even this would work
Will this approach work? It didn't work when I tried on my system. Just want to confirm if it's even possible?
*.d.ts in typescript?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;
}or even this would work
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?
Solution
I use a method that first filters the fields and then combines them.
reference Exclude property from type
for interface:
reference Exclude property from type
interface A {
x: string
}
export type B = Omit & { x: number };for interface:
interface A {
x: string
}
interface B extends Omit {
x: number
}Code Snippets
interface A {
x: string
}
export type B = Omit<A, 'x'> & { x: number };interface A {
x: string
}
interface B extends Omit<A, 'x'> {
x: number
}Context
Stack Overflow Q#41285211, score: 1077
Revisions (0)
No revisions yet.