So we recently had an issue where a value was accidentally added to an array initialization which caused runtime issues.
we have an object that exports some values for Image Contrasts,
export const IMAGE_CONTRAST_VALUES = {
min: -90,
base: 0,
max: 100,
};
Then we have an array that consume those values,
const CONTRAST_VALUES = [
IMAGE_CONTRAST_VALUES.min,
IMAGE_CONTRAST_VALUES.base,
IMAGE_CONTRAST_VALUES.base,
IMAGE_CONTRAST_VALUES.max,
];
The issue was that we had 2 base entries being added to the array on init. This was never caught as the type is number[], Ideally to prevent this in the future we would have a type that requires that all the keys are included in the array, as well as in the proper order, to make sure base isn't set as the first entry of the array etc..
Initially we thought that creating a tuple of
type ImageManipulationTuple = [number, number, number]
would solve this, but it turns out that that solution is still flawed, as it allows for passing in values in the wrong order, as well as allowing multiples of same values being passed. I'm kind of stuck in progressing. Making sure the Object has it's keys defined in order and using Object.Values(IMAGE_CONTRAST_VALUES), would give us the right values, but if someone changes the order of the keys, the error would come back, anyone that can help with defining a type that forces all keys to be used in a specified order?