dotnet-websharper / core

WebSharper - Full-stack, functional, reactive web apps and microservices in F# and C#
https://websharper.com
Apache License 2.0
593 stars 52 forks source link

Record constructor is incorrectly translated #1334

Closed granicz closed 10 months ago

granicz commented 1 year ago

I have a type as follows:

[<JavaScript>]
module Client =

    [<JavaScript(false)>]
    type QRCodeAttrs =
        {
            size: int
            message: string
        }

        [<JavaScript>]
        member this.Foo() = 1

and using it as

let _ = QRCode {size=100; message="hello"}

yields in the output:

QRCode((size, message) => Create(QRCodeAttrs, {size:size, message:message}));

... which seems bogus. It should be:

QRCode(Create(QRCodeAttrs, {size:100, message:'hello'}));
granicz commented 1 year ago

Just tested this with 7.0.0.321-beta2, using:

JS.Html $"""
    <>
    {QRCode {size=100; message="hello"}}
    </>
"""

which ended up generating:

{QRCode(New(100, "hello"))}

instead of

{QRCode({size:100, message:'Hello'})}
granicz commented 1 year ago

Nevermind, that is actually correct as New is imported from the type's ESM, constructing the desired record/object.