toss / overlay-kit

The simplest and most intuitive way to manage overlays in React.
https://overlay-kit.slash.page
MIT License
295 stars 30 forks source link

chore: edit `createEvent` to infer parameter type of return function #11

Closed ho991217 closed 4 months ago

ho991217 commented 4 months ago

Previously createEvent function used a hacky method to make a parameter optional when it had undefined in its payload. However, this method made TypeScript unable to infer the names of the parameters correctly.

This resulted in issues such as:

overlay.close(payload_0: string)
overlay.closeAll(payload_0?: undefined)

TypeScript inferred the parameters as payload_0: string or payload_0?: undefined, which is not ideal. To resolve this, changes were made so that TypeScript can correctly infer the parameter types alongside the inserted EventKey.

After the changes, the parameter types are correctly inferred as:

overlay.close(overlayId: string)
overlay.closeAll()

Now, it appears the same as the documentation. The documentation correctly showed overlay.close(overlayId: string) and overlay.closeAll(), but the code did not reflect this.

Here’s a visual comparison of the before and after:

Before: overlay.close(payload_0: string) overlay.closeAll(payload_0?: undefined) overlay_1

After: overlay.close(overlayId: string) overlay.closeAll() overlay_2

Let me know if you have any comment on this issue :)

vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
overlay-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2024 4:27pm