marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
25.02k stars 5.26k forks source link

Flattened types #10350

Open sebastianbuechler opened 1 week ago

sebastianbuechler commented 1 week ago

Especially for beginners, it can be quite hard to understand the types of react-admin due to its highly reusable type structure.

For example in the DataProvider type definition we have for the getList method: getList: <RecordType extends RaRecord = any>(resource: ResourceType, params: GetListParams & QueryFunctionContext) => Promise<GetListResult<RecordType>>

However, it would be much more helpful to resolve the types directly. Like GetListParams & QueryFunctionContext could be resolved via some VS Code extension (https://marketplace.visualstudio.com/items?itemName=MylesMurphy.prettify-ts): Image

However, it's IDE-dependent and beginners probably do not know this.

What about using something like simplify from type-fest so it's directly in the codebase? https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts

Has this ever been considered?

fzaninotto commented 1 week ago

Hi, and thanks for your idea.

I agree that our reusable types produce complex IDE hints. I'm +1 for making these hints more user friendly. I'm marking this as an enhancement.

I didn't know about the Symplify type. It may be a good idea, but we must make sure that:

Finally, not all type hints are usable in an IDE. For instance, when you start typing n HTML element, IDEs suggest a list of 250 possible attributes. We don't want to spend time refining that kind of list.

My suggestion: open a PR implementing this type of simplification on a small subset of hooks and components, so that we can judge the result.