question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated tests for erased unions not working with Fable 2

See original GitHub issue

People are reporting that the automatically generated tests for erased unions are not compiling in Fable 2. See: https://github.com/fable-compiler/Fable/issues/1580#issuecomment-428425911

For example:

type VerifyErrors =
    U3<JsonWebTokenError, NotBeforeError, TokenExpiredError>

module VerifyErrors =
   let isJsonWebTokenError (v: VerifyErrors) = match v with U3.Case1 _ -> true | _ -> false

The problem is not the erased union, but JsonWebTokenError. ts2fable generates types as interfaces and Fable 2 is throwing a compile error if trying to type test against an interface because it doesn’t know how to identify the interface. Fable 1 added the interface name to types coming from F#, but this didn’t work with JS objects, so we’ve opted to be more strict in Fable 2 and avoid unexpected behaviour at runtime.

Should we stop generating these automatic matches?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
MangelMaximecommented, Nov 7, 2018

You should delete

[<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module GeoJSON =
    let ofGeometry v: GeoJSON = v |> U3.Case1
    let isGeometry (v: GeoJSON) = match v with U3.Case1 _ -> true | _ -> false
    let asGeometry (v: GeoJSON) = match v with U3.Case1 o -> Some o | _ -> None
    let ofFeature v: GeoJSON = v |> U3.Case2
    let isFeature (v: GeoJSON) = match v with U3.Case2 _ -> true | _ -> false

And others things that are looking similar to that.

0reactions
MangelMaximecommented, Feb 19, 2019

I think they still work indeed because they don’t “type check against an interface”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't type tests interfaces in Fable 2 · Issue #1580
Description Can't match erased types in Fable 2.0.0 (worked in Fable 1). ... Generated tests for erased unions not working with Fable 2...
Read more >
Better Typed than Sorry
Erased unions #. Precisely, because overloads are not supported in JS, TypeScript often uses what we call erased unions (to tell them apart...
Read more >
Interacting with JavaScript - F# |> BABEL
Fable allows the same feature by using union types and the StringEnum attribute. These union types must not have any data fields as...
Read more >
Fable 2 is Better Than Fable 3 - YouTube
I did a video exploring the shortcomings of Fable 3 recently, I thought why not do a follow up video discussing the game...
Read more >
Keeping models in sync with Reinforced.Typings
Keeping types in sync between the server and the frontend has long been a sticking point in my development career. It gives me...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found