I have these types:
interface Color {
color: string
}
type DarkerColor<T> = T & Color & { darker: string }
type ColorInfo<T> = DarkerColor<T> & {
hue: number
luminance: number
opacity?: number
}
and these functions:
function computeDarkerColor<T extends Color>(dataset: T[]): Array<DarkerColor<T>> {...}
function computeHueAndLuminance<T extends Color>(value: Array<DarkerColor<T>>): Array<ColorInfo<T>> {...}
function computeOpacity<T extends Color>(value: Array<ColorInfo<T>>): Array<Required<ColorInfo<T>>> {...}
So, basically, computeHueAndLuminance
gets in input an object (array of objects) and returns another object (array of objects) that contanins the proprerties hue
and luminance
.
The function computeOpacity
gets in input that object (array of objects) and returns the same objects (array of objects) with also the opacity
property.
To do that I thought to use a single type ColorInfo
with hue
and luminance
mandatory and opacity
optional. Then use Required
but it seems not to work. I tried also Partial
in that way:
interface Color {
color: string
}
type DarkerColor<T> = T & Color & { darker: string }
type ColorInfo<T> = DarkerColor<T> & {
hue: number
luminance: number
opacity: number
}
function computeDarkerColor<T extends Color>(dataset: T[]): Array<DarkerColor<T>> {...}
function computeHueAndLuminance<T extends Color>(value: Array<DarkerColor<T>>): Array<Partial<ColorInfo<T>>> {...}
function computeOpacity<T extends Color>(value: Array<ColorInfo<T>>): Array<ColorInfo<T>> {...}
but I get the same error:
Type 'T & Color & { darker: string; } & { hue: number; luminance: number; opacity: number; }' is not assignable to type 'Required<ColorInfo<T>>'.
What is the problem?