So confused on using '?' in flow. AFAIK (thanks to flow type question mark before or after param?):
When '?' before ':', means bar is optional, can be string or undefined:
bar?: string
When '?' after ':', means bar is maybe type, can be string, undefined, or null.
bar: ?string
My question is: In which circumstance we should the first option over the second? How about bar?: ?string
?
flow is hard...
Supported data types in an Apex class are Boolean, Integer, Long, Decimal, Double, Date, DateTime, and String. Each data type supports single values and Lists.
In programming language theory, flow-sensitive typing (also called flow typing or occurrence typing) is a type system where the type of an expression depends on its position in the control flow. In statically typed languages, a type of an expression is determined by the types of the sub-expressions that compose it.
Microsoft Dataverse (legacy) connector (CDS 2.0 connector) for Power Automate flows will be deprecated and replaced with another connector. Effective October 2022, the Microsoft Dataverse (legacy) connector, also referred to as the CDS 2.0 connector, will be deprecated.
To bring static typing to JavaScript, Flow specifies a number of syntax extensions, which are used to describe types, annotate programs, and share types between modules. Flow's syntax extensions are only additions which can be easily stripped away and don't change the runtime behavior of JavaScript in any way.
Optional means that the property can be omitted. Have a look at this example:
type Foo = {
optional?: string
}
const foo: Foo = {}; // OK
type Bar = {
maybe: ?string;
}
const bar: Bar = {}; // Error: `maybe` is missing in object literal
Regarding combination of optional and maybe - it allows assigning null
to optional property:
type Baz = {
maybeAndOptional?: ?string;
}
let baz: Baz = {}; // OK
baz = { maybeAndOptional: null }; // OK
type Foo = {
optional?: string
}
let foo: Foo = {}; // OK
foo = { optional: null } // Error: null is incompatible with string
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