Is there a way to extend a function in an interface to include a property in TypeScript?

Viewed 49

I have an existing interface in typescript that contains a function:

interface Example {
  foo(): void;
}

This interface belongs to a library and is declared in @types/example.

Recent changes to the library have introduced a function property of that function. I would like to redeclare the interface locally as:

interface Foo {
  (): void;
  bar(): void;
}

interface Example {
  foo: Foo;
}

that way when I have an Example instance, I can call example.foo.bar().

Unfortunately, due to the existing declaration, I can't redeclare foo as it errors with:

Subsequent property declarations must have the same type. Property 'foo' must be of type '() => void', but here has type 'Foo'.

Is there a way to extend the existing interface to make this work without modifying the interface in @types/example?

0 Answers
Related