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

mutable variables become immutable #393

Closed
Booksbaum opened this issue Mar 26, 2021 · 0 comments
Closed

mutable variables become immutable #393

Booksbaum opened this issue Mar 26, 2021 · 0 comments

Comments

@Booksbaum
Copy link
Contributor

export declare module M {
    var v2: number;
    let l1: number;
    const c1: number;
}

==>

module M =
    type [<AllowNullLiteral>] IExports =
        abstract v1: float
        abstract l1: float
        abstract c1: float

v1 and l1 should be mutable:

module M =
    type [<AllowNullLiteral>] IExports =
        abstract v1: float with get,set
        abstract l1: float with get,set
        abstract c1: float
Booksbaum added a commit to Booksbaum/ts2fable that referenced this issue Mar 28, 2021
Works with variables in modules & namespaces.

Doesn't work with top-level variables:
```typescript
export let v: number;
```
`v` is mutable and should be converted into:
```fsharp
let [<Import(...)>] mutable v: float = jsNative
```
BUT: ts2fable places everything in a recursive module:
```fsharp
module rec Name
open System
//...
let [<Import(...)>] mutable v: float = jsNative
```
In a rec module, mutable let bindings aren't allowed:
> error FS0874: Mutable 'let' bindings can't be recursive or defined in
recursive modules or namespaces

-> would require change of generated code for top-level variables.
Instead these variables are still immutable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant