I’ve been working on creating a ambient definitions file for flot as an exercise in learning some TypeScript, but I’ve encountered this problem multiple times in the documentation for flot (in the axis options):
ticks: null or number or ticks array or (fn: axis -> ticks array)
So I could do this in my axisOptions interface:
interface axisOptions {
ticks?: any;
}
Which covers all possible options, but is there a better way to restrict it to a number, an array (of numbers) or a function, but not anything else?
You can’t currently specify multiple types – in fact this is the perfect use of the dynamic
anytype because although it isn’t “anything” it is certainly dynamic.To enforce the types on a dynamic type, you would have to check it – like in this example: