'Multiple inheritance workarounds
I'm trying to discover a pattern for combining multiple interfaces into one abstract class. Presently I can combine multiple interfaces via implements, but an interface cannot declare a constructor. When I must introduce a constructor I'm forced to use an abstract class. When I use a abstract class I must re-declare the entire composite interface! Surely I'm missing something?
interface ILayerInfo {
a: string;
}
interface ILayerStatic {
b(): string;
}
class Layer implements ILayerInfo, ILayerStatic {
constructor(info: ILayerInfo);
a: string;
b(): string;
}
ANSWER: Use new:
interface Layer extends ILayerInfo, ILayerStatic {
new(info: ILayerInfo);
}
// usage: new Layer({ a: "" });
Solution 1:[1]
Here's a sample of a solution for inheriting multiple interfaces:
type ShowAllWithTypography = TypographyClampProps & ShowAllProps
interface Props extends ShowAllWithTypography
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shah |
