Support optional component props generic in `NiceModalArgs`?
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 127
- PR merge metrics
- No merged PRs in 30d
Description
Hello, thanks for this great tool, it's a joy to work with!
When passing optional props to the registered modal component (and the component type passes a condition in type NiceModalArgs<T>), the component props are typed as Partial<Omit<React.ComponentProps<T>, 'id'>>.
Using Partial<> means that otherwise required component props are incorrectly loosened up. The related comment specifically mentions using Partial<>, so I guess there was a good reason to do so. But to achieve type safety, now a wrapper function must be used that enforces the required component props:
function registerModalWithProps<C extends React.FC<any>>(id: string, component: C, props: React.ComponentProps<C>) {
register(id, component, props)
}
Could this situation be avoided if an optional component props generic were to be introduced?
type ReactJSXOrConstructor<T> = T extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any> ? T : never
type PartialComponentProps<T> = Partial<React.ComponentProps<ReactJSXOrConstructor<T>>>
declare type NiceModalArgs<T, P = PartialComponentProps<T>> = T extends ReactJSXOrConstructor<T> ? Omit<P, 'id'> : Record<string, unknown>;
I understand the optional generic would creep into the signatures of useModal(), register(), and possibly even show(), so an on-demand wrapper function might be simpler overall.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/index.tsx around line 210, where NiceModalArgs and its Partial<> behavior are defined, then trace the useModal(), register(), and show() signatures mentioned in the issue. Done means required component props remain type-safe while the proposed optional props generic works consistently across those APIs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100