diff --git a/.changeset/little-impalas-warn.md b/.changeset/little-impalas-warn.md
new file mode 100644
index 000000000000..e879fd8e265f
--- /dev/null
+++ b/.changeset/little-impalas-warn.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+fix: allow `asset(...)` to be used with imported assets
diff --git a/documentation/docs/98-reference/20-$app-types.md b/documentation/docs/98-reference/20-$app-types.md
index 51b88c66cdad..97053e762869 100644
--- a/documentation/docs/98-reference/20-$app-types.md
+++ b/documentation/docs/98-reference/20-$app-types.md
@@ -15,12 +15,12 @@ import type { RouteId, RouteParams, LayoutParams } from '$app/types';
## Asset
-A union of all the filenames of assets contained in your `static` directory.
+A union of all the filenames of assets contained in your `static` directory, plus a `string` wildcard for asset paths generated from `import` declarations.
```dts
-type Asset = '/favicon.png' | '/robots.txt';
+type Asset = '/favicon.png' | '/robots.txt' | (string & {});
```
diff --git a/packages/kit/src/core/sync/write_non_ambient.js b/packages/kit/src/core/sync/write_non_ambient.js
index c2b4a57025c8..df55a3cbee0d 100644
--- a/packages/kit/src/core/sync/write_non_ambient.js
+++ b/packages/kit/src/core/sync/write_non_ambient.js
@@ -91,6 +91,8 @@ function generate_app_types(manifest_data) {
layouts.push(layout_type);
}
+ const assets = manifest_data.assets.map((asset) => s('/' + asset.file));
+
return [
'declare module "$app/types" {',
'\texport interface AppTypes {',
@@ -99,7 +101,7 @@ function generate_app_types(manifest_data) {
`\t\tLayoutParams(): {\n\t\t\t${layouts.join(';\n\t\t\t')}\n\t\t};`,
`\t\tPathname(): ${Array.from(pathnames).join(' | ')};`,
'\t\tResolvedPathname(): `${"" | `/${string}`}${ReturnType}`;',
- `\t\tAsset(): ${manifest_data.assets.map((asset) => s('/' + asset.file)).join(' | ') || 'never'};`,
+ `\t\tAsset(): ${assets.concat('string & {}').join(' | ')};`,
'\t}',
'}'
].join('\n');
diff --git a/packages/kit/src/core/sync/write_types/index.spec.js b/packages/kit/src/core/sync/write_types/index.spec.js
index 6ea35f7534d9..8de69589607f 100644
--- a/packages/kit/src/core/sync/write_types/index.spec.js
+++ b/packages/kit/src/core/sync/write_types/index.spec.js
@@ -46,7 +46,7 @@ test('Creates correct $types', { timeout: 60000 }, () => {
execSync('pnpm testtypes', { cwd: path.join(cwd, dir) });
} catch (e) {
console.error(/** @type {any} */ (e).stdout.toString());
- throw new Error('Type tests failed');
+ throw new Error(`${dir} type tests failed`);
}
}
});
diff --git a/packages/kit/src/runtime/app/paths/types.d.ts b/packages/kit/src/runtime/app/paths/types.d.ts
index 8f0e2f4ebaed..9e7c8e77e5a4 100644
--- a/packages/kit/src/runtime/app/paths/types.d.ts
+++ b/packages/kit/src/runtime/app/paths/types.d.ts
@@ -56,7 +56,7 @@ export function resolve(...args: ResolveArgs):
* import { asset } from '$app/paths';
*
*
- *
+ *
* ```
* @since 2.26
*/
diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts
index eefee3fce494..6c7fc61b4492 100644
--- a/packages/kit/types/index.d.ts
+++ b/packages/kit/types/index.d.ts
@@ -2770,7 +2770,7 @@ declare module '$app/paths' {
* import { asset } from '$app/paths';
*
*
- *
+ *
* ```
* @since 2.26
*/