'typescript type for single and array properties
I have following use case for TypeScript types:
I have a certain interface, e.g:
interface Data {
a: number;
b: string;
}
and I need these interfaces:
interface DataSingleValue {
a: number;
b: string;
}
interface DataArrayValue {
a: number[];
b: string[];
}
So the interfaces do have all properties of the Data-interface with the same data type. Just in one case they are all arrays.
I have a lot of such interfaces and I would like to have something like this:
interface Model<T | T[]> {// dont know how to do}
interface DataSingleValue extends Model<Data> {} --> leads to the same as above
interface DataArrayValue extends Model<Data[]> {} -> leads to the same as above
How to do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
