Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to support literal value in type? #111

Open
MangelMaxime opened this issue Jul 15, 2024 · 0 comments
Open

How to support literal value in type? #111

MangelMaxime opened this issue Jul 15, 2024 · 0 comments
Labels
area:converter question Further information is requested syntax support

Comments

@MangelMaxime
Copy link
Contributor

Issue created from Glutinum Tool

Glutinum version - 0.9.0-preview

TypeScript

type LiteralBool = { log: true }

FSharp

module rec Glutinum

open Fable.Core
open Fable.Core.JsInterop
open System

[<AllowNullLiteral>]
[<Interface>]
type LiteralBool =
    abstract member log: bool with get, set

Problem description

TypeScript allows to pass literal values in the type but not F#.

To support this syntax, we currently transform the literal value to its type representation. But this means that people could pass false instead of the only accepted value which is true.

Is there something we can do about that?

Perhaps, we could use Emit to generate on the fly the POJO but is it worth the complexity?

module rec Glutinum

open Fable.Core
open Fable.Core.JsInterop
open System

[<Global>]
[<AllowNullLiteral>]
type options
    [<Emit("{name: $0, log: true}")>]
    (
        name : string,
        log: bool
    ) =

    member val log : bool = nativeOnly with get, set

let o = options("maxime", false) // I on purpose used false here to show that the output always use true

generates

export const o = {name: "maxime", log: true};

This is correct but can be confusing for the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:converter question Further information is requested syntax support
Projects
None yet
Development

No branches or pull requests

1 participant