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
{{ message }}
Repository navigation
Error: FSharp.Reflection: Microsoft.FSharp.Core.FSharpOption`1 is not an F# union type #4082
Unable to process the message: [*removed*] Error: Microsoft.FSharp.Core.FSharpOption`1 is not an F# union type
getUnionCases Reflection.js:310
getCaseName Program.fs:25
ElmishDebug_getMsgNameAndFields Program.fs:47
program_4 Program.fs:54
update program.fs:92
[...]
And indeed the type object has undefined cases.
I verified in an F# interactive console and it does work as expected out of Fable:
> FSharp.Reflection.FSharpType.GetUnionCases(typeof<option<string>>);;valit:Reflection.UnionCaseInfo array =[|FSharpOption`1.None
{DeclaringType = Microsoft.FSharp.Core.FSharpOption`1[System.String];
Name ="None";
Tag =0;};
FSharpOption`1.Some
{DeclaringType = Microsoft.FSharp.Core.FSharpOption`1[System.String];
Name ="Some";
Tag =1;}|]
Is it a known shortcoming of the reflection implementation in Fable that option types are not considered union cases?
Or is it a bug that needs fixing?
(I suspect it's a known shortcomings, because it seems too big to have been missed by inadvertence... but strangely I couldn't find an issue mentioning this?)
changed the title [-]Error: FSharp.Reflection: `Microsoft.FSharp.Core.FSharpOption`1` is not an F# union type[/-][+]Error: FSharp.Reflection: Microsoft.FSharp.Core.FSharpOption`1 is not an F# union type[/+]on Mar 16, 2025
Ah, actually the issue might not be where I though it was...
I'm still not sure whether it's normal that an option is not seen as a DU in Fable compiled code, but the root cause of my initial error seems to be a discrepancy in the behaviour of Microsoft.FSharp.Reflection.FSharpType methods vs Fable.Core.Reflection methods, probably due to the erasure of options.
The pull request was not created — a fallback review issue was created instead due to protected file changes: #4530
🤖 This is an automated response from Repo Assist.
I've submitted a draft PR that addresses this issue: I investigated the root cause and found that option_type() in fable-library-ts/Reflection.ts (and the equivalent in fable-library-py/fable_library/reflection.py) was building a TypeInfo without a cases property — the exact field that FSharpType.IsUnion and GetUnionCases rely on.
The fix rewrites option_type() to expose None (tag 0) and Some (tag 1) as union cases, and adds option-aware handling in getUnionFields/makeUnion to account for Fable's erased option representation at runtime.
Please check the PR for details and test coverage. CI will validate the build.
Activity
[-]Error: FSharp.Reflection: `Microsoft.FSharp.Core.FSharpOption`1` is not an F# union type[/-][+]Error: FSharp.Reflection: Microsoft.FSharp.Core.FSharpOption`1 is not an F# union type[/+]mlaily commentedon Mar 16, 2025
Ah, actually the issue might not be where I though it was...
I'm still not sure whether it's normal that an option is not seen as a DU in Fable compiled code, but the root cause of my initial error seems to be a discrepancy in the behaviour of
Microsoft.FSharp.Reflection.FSharpTypemethods vsFable.Core.Reflectionmethods, probably due to the erasure of options.The following code:
Displays the following in a console:
The union case seen by
Fable.Core.Reflectionis actually not the option, but the wrapped value! (which is itself a custom DU)So mixing reflection calls from both namespaces at the same time seems very error prone...
EDIT: this has been fixed here elmish/browser#77
I'm still curious about your expert opinion on this:
Microsoft.FSharp.ReflectionorFable.Core.Reflection?kerams commentedon Mar 21, 2025
Related #2110
Fix option<'T> not recognized as union type in reflection (fixes #4082)
github-actions commentedon Apr 12, 2026
Note
The pull request was not created — a fallback review issue was created instead due to protected file changes: #4530
🤖 This is an automated response from Repo Assist.
I've submitted a draft PR that addresses this issue: I investigated the root cause and found that
option_type()infable-library-ts/Reflection.ts(and the equivalent infable-library-py/fable_library/reflection.py) was building aTypeInfowithout acasesproperty — the exact field thatFSharpType.IsUnionandGetUnionCasesrely on.The fix rewrites
option_type()to exposeNone(tag 0) andSome(tag 1) as union cases, and adds option-aware handling ingetUnionFields/makeUnionto account for Fable's erased option representation at runtime.Please check the PR for details and test coverage. CI will validate the build.