Describe the bug
With the latest SvelteKit 3, using resolve() with asset paths from src/service-worker/index.ts results in a TypeScript error.
The path property of the assets is typed as string, while resolve() appears to only accept a generated union of known route/path literals.
For example:
import { version } from '$app/env';
import { resolve } from '$app/paths';
import { immutable, assets } from '$app/service-worker';
const CACHE = `cache-${version}`;
const ASSETS = [
...immutable.map((asset) => resolve(asset.path)),
...assets.map((asset) => resolve(asset.path))
];
TypeScript reports:
Argument of type 'string' is not assignable to parameter of type
'[pathname: ""] | [pathname: "poem"] | [pathname: "poem/editor"] |
[pathname: "search"] | [pathname: `#${string}`] |
[pathname: `?${string}`] | [pathname: `poem#${string}`] |
[pathname: `poem/editor#${string}`] |
[pathname: `poem/editor?${string}`] |
[pathname: `poem?${string}`] |
[pathname: `search#${string}`] |
The error is reported at: resovle(asset.path)
because asset.path is typed as string, whereas resolve() expects its pathname argument to be one of the generated route literals.
workaround
const ASSETS: string[] = [
...immutable.map((asset) => resolve<any>(asset.path)), // the Vite output
...assets.map((asset) => resolve<any>(asset.path)) // everything in `static`
]
Reproduction
import { version } from '$app/env';
import { resolve } from '$app/paths';
import { immutable, assets } from '$app/service-worker';
const CACHE = `cache-${version}`;
const ASSETS = [
...immutable.map((asset) => resolve(asset.path)),
...assets.map((asset) => resolve(asset.path))
];
Logs
System Info
Severity
annoyance
Additional Information
No response
Describe the bug
With the latest SvelteKit 3, using
resolve()with asset paths fromsrc/service-worker/index.tsresults in a TypeScript error.The path property of the assets is typed as string, while resolve() appears to only accept a generated union of known route/path literals.
For example:
TypeScript reports:
The error is reported at:
resovle(asset.path)because
asset.pathis typed asstring, whereasresolve()expects its pathname argument to be one of the generated route literals.workaround
Reproduction
Logs
System Info
Severity
annoyance
Additional Information
No response