Like in Go you can use:
func add(x, y int) int {
return x + y
}
func main() {
fmt.Println(add(42, 13))
}
This is really concise and readable at the same time, and helps to shorten the function declaration.
For example:
function store(file, section, attribute, field: string, value: any) {
}
// instead of
function store(file: string, section: string, attribute: string, field: string, value: any) {
}
This is really too specific case to introduce special syntax for it.
This syntax is already allowed and means a different thing.
Even if it was possible, I find readability of this construct is pretty bad. If there are more than one or two parameters I instead use multiple lines, IMO much more readable:
function store(
file: string,
section: string,
attribute: string,
field: string,
value: any
): void {
// ....
}
Alternatively, when there are more than 3 or 4 parameters, I may use an object and create a type for that object, then the parameter type is just the name of that object. I add a JSDoc for the type to get inline popup info/help for the type from the IDE.
/**
* Some text
* @typedef {Object} ParamsType
* @param {string} file Some explanation
* @param {string} section
* @param {string} attribute
* @param {string} field
* @param {*} value
*/
type ParamsType = {|
file: string,
section: string,
attribute: string,
field: string,
value: any
|};
/**
* As short as it gets
* @param {ParamsType} o
*/
function store(o: ParamsType): void {
// ....
}
This syntax means something else in flow already:
func f(x, y: int): int
namely, infer the first argument and require the second to be an int. If anyone feels like proposing alternative syntax, feel free to comment or open another issue with said proposal.
Most helpful comment
This is really too specific case to introduce special syntax for it.