elmish / hmr

Hot Module Replacement for Elmish apps
https://elmish.github.io/hmr
Other
28 stars 9 forks source link

Error Partially Qualified Path #33

Closed JoschuaL closed 2 years ago

JoschuaL commented 2 years ago

Description

When trying to use HMR out in a template, when I try to compile the project after adding

open Elmish.HMR

Below the other open statements, the compilation fails with the message

src/Main.fs(9,6): (9,16) error FSHARP: This declaration opens the namespace or module 'Lit.Elmish.HMR' through a partially qualified path. Adjust this code to use the full path of the namespace. This change will make your code more robust as new constructs are added to the F# and CLI libraries. (code 893)

Repro code

The template is https://github.com/AngelMunoz/Fable.Lit.Templates/tree/main/templates/elmish-lit

I did nothing aside from adding Fable.Elmish.HMR using femto

femto src/App.fsproj install Fable.Elmish.HMR

added open Elmish.HMR below the other open statements.

the final code

module Main

Fable.Core.JsInterop.importSideEffects "./styles.css"

open Elmish

open Lit
open Lit.Elmish
open Elmish.HMR

type State = { counter: int; name: string }

type Msg =
    | Increment
    | Decrement
    | Reset

let private init _ = { counter = 0; name = "World" }

let private update msg state =
    match msg with
    | Increment ->
        { state with
              counter = state.counter + 1 }
    | Decrement ->
        { state with
              counter = state.counter - 1 }
    | Reset -> init state

let private counter
    (props: {| counter: int
               decrement: unit -> unit
               reset: unit -> unit
               increment: unit -> unit |})
    =
    html
        $"""
        <button @click={fun _ -> props.decrement ()}>-</button>
        <button @click={fun _ -> props.reset ()}>Reset</button>
        <button @click={fun _ -> props.increment ()}>+</button>
        <div>{props.counter}</div>
        """

let view state dispatch =
    let counterEl =
        counter
            {| counter = state.counter
               decrement = fun _ -> dispatch Decrement
               increment = fun _ -> dispatch Increment
               reset = fun _ -> dispatch Reset |}

    html
        $"""
        <div>Hello {state.name}!</div>
        {counterEl}
        """

Program.mkSimple init update view
|> Program.withLit "elmish-lit"
|> Program.run

Expected and actual results

Expected the program to compile and run after exectuting npm start

Actual result is the error message mentioned above.

Related information

MangelMaxime commented 2 years ago

I don't think the problem comes from Fable.Elmish.HMR but from Elmish.Lit.

If you try to write:

open Lit
open Lit.Elmish
open Elmish.HMR

Even without Fable.ELmish.HMR you will have the same error.

However looking at Lit.Elmish.HMR.fs implementation I don't see which RequiredQualifiedAccess attributes is causing that.

You can change your code to:

open Lit.Elmish
open Elmish.HMR
open Lit

To have the error goes away.

MangelMaxime commented 2 years ago

The HMR code has been removed from Fable.Lit so this error should not occur now