After reading a tutorial on extending interfaces in TypeScript, I learned that it's possible to extend a third-party library interface by simply defining another interface with the exact same name. The example provided in the tutorial demonstrated this concept:
// third-party source
interface jQueryElement {
data(name: string): any;
data(name: string, data: any): jQueryElement;
}
// my code
interface jQueryElement {
todo(): Todo;
todo(todo: Todo): void;
}
However, one question still remains: How do you import these extended interfaces without causing name collisions?
As someone who has only worked with TypeScript within Angular projects and not standalone, I'm curious if I can use the same approach or if I should define a new interface using extends
like so:
interface jQueryElement2 extends jQueryElement {
todo(): Todo;
todo(todo: Todo): void;
}