rescript-lang / rescript-lang/rescript-react

Implicit type conversion?

オープン
#105 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
ReScript
スター
517
フォーク
45
PR マージ指標
30日以内にマージされた PR はありません

説明

Hello,
I’m exploring rescript-react and noticed a peculiar behaviour. Here’s my test code:

module MyComponent = {
  @react.component
  let make = () => {
    let (value, setValue) = React.useState(_ => 0)
    <>
      <div> {React.string(string_of_int(value))} </div>
      <input
        onChange={evt => {
          let x = ReactEvent.Form.target(evt)["value"] // 1
          setValue(_ => x) // 2
        }}
      />
    </>
  }
}

What I noticed is that on the line marked with // 1 the type of x is 'a, but on line // 2 hovering over x shows the type int. Why is that? I would expect the compiler to ask me to decode the value of x.

Thank you in advance!

P.S.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供されたコンポーネント内の ReactEvent.Form.target(evt)["value"] 式と useState セッターから始め、リンク先の Playground を使って動作を再現します。結果をリンク先のフォーラムスレッドと比較し、推論された型が意図的なものかどうかを判断します。動作が明確になるか、リポジトリへの具体的な変更が特定できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
react
領域
frontend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。