I was looking at the docs for a flux store in React. They gave the following example.
import {ReduceStore} from 'flux/utils';
class CounterStore extends ReduceStore<number> {
getInitialState(): number {
return 0;
}
reduce(state: number, action: Object): number {
switch (action.type) {
case 'increment':
return state + 1;
case 'square':
return state * state;
default:
return state;
}
}
}
See getInitialState(): number {}, this doesn't seem to follow any previous javascript syntax convention. How would one write this using ES5 syntax?
That is Typescript and it is annotating what type of value the function returns. getInitialState returns a number.
You can see the same annotation in the arguments being passed to reduce(). This sort of annotation lets your IDE/text editor do some really helpful suggestions and error checking.
This is not part of ES6 syntax. You're looking at type definitions for static type checkers, such as flowjs or TypeScript. There is no ES5 syntax for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With