My goal seems simple to me, but I am realizing that my experience with Typescript might not be enough.
I want to create a type that can accept the following expressions:
const dp: DataPoint = [1, 2];
const dp2: DataPoint = [1, 2, 3];
const dps: DataPoints = [[1, 2], [2, 3]];
const dps2: DataPoints = [[1, 2, 3], [2, 3, 4]];
I've attempted the following:
export type DataPoint<T = number, D = number> = [number, T, D?];
export type DataPoints<T = number, D = number> = DataPoint<T, D>[];
I've tried various methods, but they all seem to result in types with two generics:
DataPoint<number, number>
or DataPoints<number, number>
.
Is there a way for it to infer never
from the example of dp
and have DataPoint<number>
instead of
<DataPoint<number, number>
?