Skip to content

[TS] invalid TS emited for mutable structs #4453

@goswinr

Description

@goswinr

When targeting Typescript mutable fields on structs cause the struct to be wraped in FSharpRef<_> , but then the access to the field fails to compile
This happens only when there is mutable after val

[<Struct>]
type R =

    val mutable X: float

    new(x: float) = { X = x }

    member this.IsEmpty() =
        // emits invalid TS
        // Property 'X' does not exist on type 'FSharpRef<Rt>'.
        this.X < 0.0

compiles to

export class R extends Record implements IEquatable<R>, IComparable<R> {
    X: float64;
    constructor(X: float64) {
        super();
        this.X = X;
    }
}

export function R__IsEmpty(this$: FSharpRef<R>): boolean {
    return this$.X < 0; // Property 'X' does not exist on type 'FSharpRef<Rt>'.
}

why is FSharpRef<_> needed here?

Tested on 5.rc5 and in REPL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions