mui / mui/material-ui

[TextField] TS error when TextField select multiple onChange signature uses 2 arguments

Open
#34,816 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

scope: text field type: bug typescript
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Steps to reproduce 🕹

Steps:

  1. Create TextField with select prop and SelectProps[mulitple]
  2. Pass a function with two arguments as you would when using Select with multiple
Current behavior 😯

TS will throw error

Type '(e: any, child: any) => void' is not assignable to type 'ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>'.
Expected behavior 🤔

When using multiple select, the second argument is the clicked option. Putting the @ts-ignore on the error and console logging the second argument will show the object, as you would on the Select component.

Context 🔦

No response

Your environment 🌎
npx @mui/envinfo
  System:
    OS: Windows 10 10.0.19042
    CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor
    Memory: 11.70 GB / 31.93 GB
  Binaries:
    Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.5.5 - C:\Program Files\nodejs\npm.CMD
    Watchman: 20210102.202219.0 - C:\Users\roger\watchman\bin\watchman.EXE
  Utilities:
    Git: 2.30.0.
  IDEs:
    Android Studio: AI-212.5712.43.2112.8815526
    VSCode: 1.71.2 - C:\Users\roger\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD
    Visual Studio: 15.9.28307.1401 (Visual Studio Community 2017)
  Languages:
    Bash: 5.0.17 - C:\Windows\system32\bash.EXE
    Java: 17.0.1
    Python: 2.7.18
  Databases:
    PostgreSQL: 10.15 - C:\Program Files\PostgreSQL\10\bin\postgres.EXE
    SQLite: 3.32.2 - C:\platform-tools\sqlite3.EXE
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (106.0.1370.47)
    Internet Explorer: 11.0.19041.1202

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TextField and Select type definitions and reproduce the reported TypeScript error using a multiple select and a two-argument onChange callback. Done means the callback matches the multiple-select behavior without @ts-ignore and the reported type error is gone.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.