Flow中能否为多个类变量统一声明同一数据类型?
Does Flow support declaring multiple class properties with the same type in one line?
Hey there! As someone who’s worked with Flow for a while, I hate to break it to you, but Flow does NOT support the shorthand syntax you’re hoping for—where you declare multiple class properties with the same type in a single line like name, nickName : string;.
Let me clarify this with examples:
- In Java, grouping multiple variable declarations of the same type is totally valid:
public class Person { String name, nickName; } - But Flow requires explicit type annotations for each individual class property. Your current working code is actually the correct, supported way to write this in Flow:
// @flow export default class Person { name : string; nickName : string; }
I’ve dug through the official Flow docs and community discussions too, and there’s no indication this syntax is supported now or planned for future updates. So for the time being, you’ll have to stick with annotating each property separately.
内容的提问来源于stack exchange,提问作者theapache64
相关产品推荐
相关产品推荐

