Skip to content

IsUnion returns false for typeof<Option<int>> #2110

Closed

Description

@kerams

Description

Reflection.FSharpType.IsUnion typeof<Option<int>> returns false.

Expected and actual results

Expecting true like on .NET.

Related information

  • Fable version: Online REPL

Activity

  1. alfonsogarciacaro commented on Jul 1, 2020

    @alfonsogarciacaro
    Member

    Yes, in Fable option is a special type and is not like other unions. Although I guess we could fix it in the reflection info.

    export function option_type(generic: TypeInfo): TypeInfo {
    return new TypeInfo("Microsoft.FSharp.Core.FSharpOption`1", [generic]);
    }

    Do you have an example of a scenario that's being blocked by this?

  2. kerams commented on Jul 1, 2020

    @kerams
    ContributorAuthor

    https://github.com/Zaid-Ajaj/Fable.Remoting/pull/158/files#diff-5bdc4da2122faa430fe9e2f88bdb24e6R425

    Not really a blocker since one can always specifically typecheck for Option.

  3. github-actions commented on Apr 17, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    This issue is addressed by draft PR #4529: Fix FSharpOption not recognized as union type in F# reflection.

    The root cause is that option_type() in fable-library-ts/Reflection.ts and fable-library-py/fable_library/reflection.py creates a TypeInfo without a cases property, so:

    • FSharpType.IsUnion(typeof<option<int>>) returns false
    • FSharpType.GetUnionCases(typeof<option<int>>) throws
    • FSharpValue.GetUnionFields and MakeUnion also fail for option types

    PR #4529 rewrites option_type() to expose None (tag 0) and Some (tag 1) as union cases, and adds option-aware handling in getUnionFields/makeUnion to deal with Fable's erased runtime representation (None = undefined/null, Some(x) = x directly).

    Generated by 🌈 Repo Assist, see workflow run. Learn more.

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@8f2d44f5d624e31c4af7cdbd948c6f5eba875a85
    
  4. MangelMaxime commented on May 28, 2026

    @MangelMaxime
    Member

    Fixed in #4529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions