I have a main TypeScript project distributed as a package that can be enriched by plugins (which are just other TypeScript packages).
My main project exposes an API with a definition like below
class Dealer {
public buyCar (model: string, options: any): void {
// ...
}
}
So let's suppose the main project allows to buy cars from a dealer, and that the plugins can add new car models available to buy. How can I extend the buyCar definition from the plugin package in order to add more specific types?
Something like
class Dealer {
public buyCar (model: "Toyota", options: ToyotaOptions): void;
}
I know I can do this from the main project, but the point is that the main project shouldn't be aware of the plugins, so plugins must extend the interfaces.
from How to extend TypeScript interfaces of a dependency
No comments:
Post a Comment