Some Inputs with choices in their props do not accept `ReadonlyArray<T>`.
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- react, typescript
- 领域
- frontend
调研方向
从 packages/ra-core/src/form/useChoices.tsx 的 L16 开始,然后使用 SelectInput 示例以及 L129 和 L151 处链接的 StackBlitz 代码重现 TypeScript 错误。按建议检查其他基于 choice 的输入;当 readonly choices 能够在没有 TypeScript 错误的情况下得到一致接受时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
What you were expecting:
SelectInput choices should accept ReadonlyArray<T>
What happened instead:
SelectInput choices does not accept ReadonlyArray<T>
Steps to reproduce:
- use
"react-admin": "^4.12.3"
Related code:
- Preferably, a sandbox forked from
- L129
- L151
https://stackblitz.com/edit/github-h13gjc?file=src%2Fposts%2FPostEdit.tsx
- A link to a GitHub repo with the minimal codebase to reproduce the issue
import { SelectInput } from 'react-admin';
type Choice = {
id: number;
name: string;
};
const mutableArray = [
{
id: 1,
name: 'foo',
},
{
id: 2,
name: 'bar',
},
{
id: 3,
name: 'baz',
},
] satisfies Array<Choice>;
const readonlyArray = [
{
id: 1,
name: 'foo',
},
{
id: 2,
name: 'bar',
},
{
id: 3,
name: 'baz',
},
] as const satisfies ReadonlyArray<Choice>;
export const SelectInputGroup = () => {
return (
<>
<SelectInput source="mutableChoices" choices={mutableArray} />
<SelectInput source="immutableChoices" choices={readonlyArray} /> // type error
</>
);
};
Other information:
My suggestion (though more than just the SelectInput needs to be inspected):
- choices?: any[];
+ choices?: readonly any[]; // or ReadonlyArray<any>
Environment
- React-admin version: 4.12.3
- Last version that did not exhibit the issue (if applicable):
- React version: 18.2.0
- Browser: Google Chrome 115.0.5790.114 (Official Build) (arm64)
- Stack trace (in case of a JS error):
- 主要语言
- TypeScript
- 星标
- 27k
- 派生
- 5.5k
- 平均合并
- 1 天 3 分钟
- 30 天内合并 PR
- 32
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
marmelab/react-admin 的其他 Issue
-
Blank page after logout when the app re-renders `<Admin>` during `authProvider.logout()`可能已有人在做 @uchiha-suraj 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
marmelab/react-admin#11431 · 1 条评论 ·
维护者通常 1 天内回复
-
Pagination: page button aria-labels are not translated on small screens可能已有人在做 @Singmin 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
marmelab/react-admin#11427 ·
维护者通常 1 天内回复
-
Add emptyText property to SelectArrayInput可能已有人在做 @kwitykwity 于 61 天前认领。 未关闭enhancement good first issue
难度 2/5 1-3 小时 新手友好度 72/100
marmelab/react-admin#10454 · 7 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 一周以上 新手友好度 38/100
marmelab/react-admin#11426 · 1 个 reaction ·
维护者通常 1 天内回复
-
ra-data-graphql-simple: outdated graphql-ast-types-browser dependency causes npm peer warnings可能重新可做 @bipul724 于 14 天前认领,目前没有进行中的 PR。 未关闭
难度 4/5 3-5 天 新手友好度 25/100
marmelab/react-admin#11395 · 1 条评论 ·
维护者通常 1 天内回复
查看 marmelab/react-admin 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
Northeastern-Electric-Racing/FinishLine#4660 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
mihaip/infinite-mac#475 ·
-
Let TypeScript accept an initial object in ReactiveDict可能已有人在做 @yograj-vijay-yadav 今天认领。 未关闭bug good first issue help wanted workshop
难度 2/5 1-3 小时 新手友好度 92/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
marmelab/atomic-crm#401 ·
维护者通常 1 天内回复
-
account: profile
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 5 天内回复