You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been using an "enum" pattern with Flow that makes it a little easier to work with types.
First, I define some constants where they have a Literal Type for a specific string. Then I use these constants to build an object with some accessor keys. Finally, I use $Values to grab the types of each value and build a string enum for the type. Here's a real example from my application:
I can confirm that this pattern works fine with vanilla Flow, and Flow will raise an error if I try to assign "foo" to a variable with the FieldType type.
However, it looks like flow-runtime is struggling with these literal types, and it turns everything into string | string | string | ...
I am trying to see if I can use flow-runtime to automatically extract some of these enums and use them in other parts of my application (in a different programming language.)
Doesn't ThingType.unwrap() cause Flow errors? I'm just curious, I had always used (reify: Type<ThingType>), .unwrap() would be nice but I assume it couldn't possibly work with Flow
This is a:
Which concerns:
Background
I have been using an "enum" pattern with Flow that makes it a little easier to work with types.
First, I define some constants where they have a Literal Type for a specific string. Then I use these constants to build an object with some accessor keys. Finally, I use
$Values
to grab the types of each value and build a string enum for the type. Here's a real example from my application:Then I can write code like this:
I can confirm that this pattern works fine with vanilla Flow, and Flow will raise an error if I try to assign
"foo"
to a variable with theFieldType
type.However, it looks like
flow-runtime
is struggling with these literal types, and it turns everything intostring | string | string | ...
I am trying to see if I can use
flow-runtime
to automatically extract some of these enums and use them in other parts of my application (in a different programming language.)What is the current behaviour?
Code (for https://gajus.github.io/flow-runtime/#/try)
Output:
What is the expected behaviour?
I am expecting the
widget
declaration to fail with an error like this:I am also expecting
ThingType.unwrap().toString()
to return"one" | "two" | "three"
.Workaround
In the meantime, I could change my code and manually define the string enum:
But I would love to avoid the duplication and be able to use
$Values
to extract these Literal Types.Which package versions are you using?
Latest versions on https://gajus.github.io/flow-runtime/#/try
Thank you!
The text was updated successfully, but these errors were encountered: