I have defined a custom Flow type
export type MyType = {
code: number,
type: number = 1,
}
I want the type
parameter to default as 1
if no value is present. However, Flow is complaining with Unexpected token =
.
Can this be done with Flow?
Currently using Flow v0.32.0
.
In computer technology, a default (noun, pronounced dee-FAWLT ) is a predesigned value or setting that is used by a computer program when a value or setting is not specified by the program user.
Function parameters can also have defaults. This is a feature of ECMAScript 2015.
function method(value: string = "default") { /* ... */ }
In addition to their set type, default parameters can also be void or omitted altogether. However, they cannot be null.
// @flow
function acceptsOptionalString(value: string = "foo") {
// ...
}
acceptsOptionalString("bar");
acceptsOptionalString(undefined);
acceptsOptionalString(null);
acceptsOptionalString();
https://flow.org/en/docs/types/primitives/#toc-function-parameters-with-defaults
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