2

背景

我有一个使用Elixir Desktop的小应用程序。此应用程序运行良好,启动时没有问题:

https://github.com/Fl4m3Ph03n1x/market_manager/tree/master/apps/web_interface

但是,我有透析器抱怨类型。我不确定这是否是误报,或者我做错了什么。

问题

我的MenuBar应用程序中有一些基本功能。MenuBar据我了解,这是一个 Phoenix LiveView 组件(因为它具有 amount和 arender功能)。因此,对于 Phoenix 和 LiveView 的大多数用户来说,这段代码应该看起来很熟悉:

defmodule WebInterface.Live.MenuBar do
  @moduledoc """
  Menubar that is shown as part of the main Window on Windows/Linux. In
  MacOS this Menubar appears at the very top of the screen.
  """

  use Desktop.Menu

  alias Desktop.{Menu, Window}

  @impl Menu
  def render(assigns) do
    ~H"""
    <menubar>
      <menu label="File">
          <hr/>
          <item onclick="quit">Quit</item>
      </menu>
    </menubar>
    """
  end

  @impl Menu
  def handle_event("quit", menu) do
    Window.quit()
    {:noreply, menu}
  end

  @impl Menu
  def mount(menu), do: {:ok, menu}

  @impl Menu
  def handle_info(:changed, menu), do: {:noreply, menu}

end

这里的问题是 Dialyzer 抱怨我的渲染功能:

Type mismatch for @callback render/1 in Desktop.Menu behaviour.

Expected type:
binary()

Actual type:
%Phoenix.LiveView.Rendered{
  :dynamic => (_ -> []),
  :fingerprint => 15_721_876_439_225_774_806_119_511_245_371_375_581,
  :root => true,
  :static => [<<_::1480>>, ...]
}

It says it expects a String instead of an H sigil. Which is confusing to me, because the latest version does support this sigil.

Question

So the question arises. What am I doing wrong and how can I fix this?

4

1 回答 1

1

Answer

Turns out this was a bug from the library.

The fix is already in master as my PR was accepted: https://github.com/elixir-desktop/desktop/issues/17

于 2022-01-27T16:37:40.830 回答