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
The first intuition to represents that type is to use StringEnum however this is not possible because of the general accepted string case.
One solution could be to generated a specialised Erased type:
[<RequireQualifiedAccess>]moduleForegroundColor =[<StringEnum(CaseRules.None)>][<RequireQualifiedAccess>]typeLiteral=| black
| red
[<RequireQualifiedAccess>][<Erase>]typeForegroundColor=| Literal ofForegroundColor.Literal| String ofstring
openFable.Core[<RequireQualifiedAccess>]moduleForegroundColor =[<StringEnum(CaseRules.None)>]typeLiteral=|[<CompiledName("black")>] Black
|[<CompiledName("red")>] Red
[<RequireQualifiedAccess>][<Erase>]typeForegroundColor=| Literal ofForegroundColor.Literal| String ofstringletred= ForegroundColor.Literal ForegroundColor.Red
letcustom= ForegroundColor.String "black"
Note: We needed to use CompiledName because DU cases in F# can only use lower case if marked with [<RequireQualifiedAccess>].
The problem with this second representation is that it differs from Glutinum philosophy to trying to state close the native API values for literal values.
@MangelMaxime
The type you linked in Moment.Js is only used once as parameter.
If such a type is only used as a parameter, not as a return value, an overload might be more F# idiomatic:
So the generated type is not implementing the Literal and the String case, but the function using this type as argument implements overloads:
[<StringEnum(CaseRules.None)>]typeForegroundColor=|[<CompiledName("black")>] Black
|[<CompiledName("red")>] Red
typeMyText=// overloads for `Literal` and the `String` case:abstract Draw: text: string * ?color: ForegroundColor -> unit
abstract Draw: text: string * ?color: string -> unit
It would be used like this:
(On an instance of let t = MyText() )
You are right, the point you are is a similar case as the one described in #29 (you could not know about it because I only got the time to create it now).
I am still unsure if we should or should not keep the original Erased type definition for API reference.
TypeScript documentation:
The first intuition to represents that type is to use
StringEnum
however this is not possible because of the general acceptedstring
case.One solution could be to generated a specialised Erased type:
Usage:
Another representation could be:
Note: We needed to use
CompiledName
because DU cases in F# can only use lower case if marked with[<RequireQualifiedAccess>]
.The problem with this second representation is that it differs from Glutinum philosophy to trying to state close the native API values for literal values.
Example of npm package using this features:
Moment
The text was updated successfully, but these errors were encountered: