Is there a way to create a TypeScript interface that enforces a condition where a number
property must always be less than another number
property in the interface?
For instance, if I have a numberOfFiles
property and a currentFileIndex
property, and I want to ensure that the value of currentFileIndex
is always less than numberOfFiles
, can I define this in the interface?
Would something like this be valid:
interface IProps {
numberOfFiles: number;
currentFileIndex: number<less than numberOfFiles>;
}
If it's not feasible, that's okay, but it would be helpful to know if it can be done.