TypeError useResolve "Expected 1 arguments, but got 2"
tofsjonas opened this issue · 2 comments
tofsjonas commented
If I do this, like in the example here: useResolve
import { link, useResolve, useLocation } from "svelte-navigator";
export let path;
const resolve = useResolve();
const location = useLocation();
// Force Svelte to re-run this assignement, when location changes
$: resolvedLink = resolve(path, $location);
I get this error in VSCode:
let $location: NavigatorLocation<AnyObject>
Expected 1 arguments, but got 2. ts(2554)
(Also, path
is empty, so it doesn't work unless I hardcode it, which makes the logic pointless 😢)
mefechoel commented
Yes, the second parameter is kind of a hack to force svelte to update the resolved link when the location changes. You can try casting the second argument to never
to make ts happy. Otherwise this will work, but is slightly more complex:
let resolvedLink;
$: {
if ($location) {
resolvedLink = resolve(path);
}
}
The if condition is always truthy, but again forces svelte to re run the resolve function when the location changes.
tofsjonas commented
That works, thanks! 😊