Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  152] [ 4]  / answers: 1 / hits: 24501  / 8 Years ago, wed, september 28, 2016, 12:00:00

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 =.



Flow



Can this be done with Flow?



Currently using Flow v0.32.0.


More From » flowtype

 Answers
45

You cannot have defaults in a type declaration.



Possible idea



Use a class and initialise any defaults using property initialisers : https://basarat.gitbooks.io/typescript/content/docs/classes.html#property-initializer


[#60570] Monday, September 26, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
makaylahk

Total Points: 166
Total Questions: 94
Total Answers: 117

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
;