preactjs / preact-router

:earth_americas: URL router for Preact.
http://npm.im/preact-router
MIT License
1.01k stars 156 forks source link

Add types to the Match function #422

Open tim-we opened 2 years ago

tim-we commented 2 years ago

When using preact-router with TypeScript (and strict settings) you had to explicitly type the function passed as a child to the Match component like this:

<Match path="/">{({ url }: {url: string}) => <pre>{url}</pre>}</Match>

This PR overrides the type of the children property of the Match component to provide the required types. You can now use the component as intended, even in strict mode:

<Match path="/">{({ url }) => <pre>{url}</pre>}</Match>

I also removed unused imports in match/index.d.ts and test/match.tsx.