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.

CompiledName attribute not working for union type members

See original GitHub issue

Generated union types currently contain members with different casing than the original enums. Problem is that CompiledName attribute does not work with members of union type. It works with values and functions.

Example

Following code shows that value of PPA generates a property Ppa which causes a problem during the runtime.

enum MyEnumType { Shopping PPA }

produces

type ProductLabelDomainType = | [<CompiledName "Shopping">] Shopping | [<CompiledName "PPA">] Ppa

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Zaid-Ajajcommented, Feb 5, 2022

I’d say that it’d be easier to skip the casing changes altogether

@petrkoutnycz unfortunately, GraphQL enums are not always valid as union case names by default. For example, they could be lower-case.

Until I’ve figured out why the serializers are failing in runtime, I’ve added a boolean option called normalizeEnumCases which is set to true by default (preserving current behavior) that determines whether changes to enum values should applied. To fix your issue, set this option to false in your snowflaqe.json:

{
    "normalizeEnumCases": false
}
1reaction
Zaid-Ajajcommented, Jan 19, 2022

Problem is that CompiledName attribute does not work with members of union type. It works with values and functions.

The JSON serializers at runtime know about CompiledName and it should work fine.

Are you targeting F# on dotnet or Fable?

Is your generated type missing [<Fable.Core.StringEnum>]? It should be there.

I will need more information in order to debug your issue. Snowflaqe config, JSON returned from the GraphQL API, the runtime error you are getting and how the GraphQL schema looks like.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript: check for intersections between union types ...
Typescript: check for intersections between union types, ensure all members are unique - Stack Overflow.
Read more >
Erased type-tagged anonymous union types · Issue #538
I propose we add erased union types as an F# first citizen. ... (Note using a struct union would not work well as...
Read more >
Handbook - Unions and Intersection Types
Unions with Common Fields​​ If we have a value that is a union type, we can only access members that are common to...
Read more >
F# Interop with Javascript in Fable: The Complete Guide
This is an attribute that you can attach to values, functions, members and other language constructs to override their default code generation. Next...
Read more >
Better Typed than Sorry
Precisely, because overloads are not supported in JS, TypeScript often uses what we call erased unions (to tell them apart from actual F#...
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