[Request] Improve typing of modal props
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 127
- PR merge metrics
- No merged PRs in 30d
Description
It seems not to be possible to call NiceModal.show with a strong typing of the called modal props.
Let's say that MyModal has the following props:
type Props = {
onSubmit: () => void;
name: string;
};
Then:
import NiceModal from '@ebay/nice-modal-react';
import MyModal from './components/MyModal';
const App = () => {
const onClick = () => NiceModal.show(MyModal, {
something: '123', // No error, even though `MyModal` doesn't have a `something` prop
name: '456',
}); // No error, even though prop `onSubmit` hasn't been provided
return <button onClick={onClick}>Show modal</button>;
};
It would be nice to have errors when the provided object doesn't match the type of the modal props 🙂
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 the NiceModal.show entry point and inspect how its TypeScript types infer modal props. Verify the behavior with the example shown: the compiler should reject the unknown something prop and the missing required onSubmit prop.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100