You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix NitroFetchRequest type to support string type #225
git clone https://github.com/unjs/nitro.git
cd nitro
pnpm install
pnpm dev
// after .nitro folder is created, go to any playground's route (.ts) and add following codeconstsomeDynamicUrl: string='https://test.com'$fetch(someDynamicUrl)// Error: Argument of type 'string' is not assignable to parameter of type 'NitroFetchRequest'
Describe the bug
As mention in PR comment, with the new NitroFetchRequest type for request (added in #209), user currently can't do:
constsomeDynamicUrl: string='https://test.com'$fetch(someDynamicUrl)// Error: Argument of type 'string' is not assignable to parameter of type 'NitroFetchRequest'
Proposed solution
This can be fix by adding string & {} to NitroFetchRequest in types.fetch.ts as:
the only small downside is losing type hint when quotes are already typed,
$fetch(/** cursor here */)// shows routes hints$fetch('/** cursor here */')// won't show hints, might have to tap into typescript hints using extendtion to support this?
we could also create a helper type and let users import it if they need ( another RP )
// types/fetch.tsexporttypeNitroApiRoutes=keyofInternalApi|CovertRouteToMatcher<keyofInternalApi>&{}// other.tsimport{NitroApiRoutes}from'nitropack'consturl: NitroApiRoutes="/user/:userId/post/:postId"// support best type hints (/w fussy search)
Activity