From 54fb90388f9a1723baff378bfb04a059ba8be6ff Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 16 Jul 2026 15:51:25 +0800 Subject: [PATCH] feat(assets): add TypeScript type declarations for Hugo @params module Add proper type definitions for Hugo's `@params` virtual module, configure tsconfig paths/typeRoots for resolution, and remove the @ts-expect-error suppress in color-scheme.ts. Also fix nil input handling in camel-case-keys. --- assets/js/head/color-scheme.ts | 1 - assets/js/types/params.d.ts | 8 ++++++++ assets/tsconfig.json | 6 ++++++ layouts/_partials/function/camel-case-keys.html | 2 +- layouts/_partials/init/index.html | 2 +- 5 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 assets/js/types/params.d.ts diff --git a/assets/js/head/color-scheme.ts b/assets/js/head/color-scheme.ts index 2d0eec59..650f5281 100644 --- a/assets/js/head/color-scheme.ts +++ b/assets/js/head/color-scheme.ts @@ -1,4 +1,3 @@ -// @ts-expect-error — Hugo js.Build virtual module import params from '@params' /** diff --git a/assets/js/types/params.d.ts b/assets/js/types/params.d.ts new file mode 100644 index 00000000..52268717 --- /dev/null +++ b/assets/js/types/params.d.ts @@ -0,0 +1,8 @@ +/** + * Hugo `@params` type declarations + * This file provides TypeScript type definitions for Hugo's `@params` module + */ + +declare module '@params' { + export const defaultTheme: string +} diff --git a/assets/tsconfig.json b/assets/tsconfig.json index 77e23cc5..50f3682b 100644 --- a/assets/tsconfig.json +++ b/assets/tsconfig.json @@ -4,6 +4,12 @@ "lib": ["DOM", "DOM.Iterable", "ESNext"], "module": "ESNext", "moduleResolution": "bundler", + "paths": { + "@params": ["./js/types/params"] + }, + "typeRoots": [ + "./js/types" + ], "strict": true, "noUnusedLocals": true, "allowSyntheticDefaultImports": true, diff --git a/layouts/_partials/function/camel-case-keys.html b/layouts/_partials/function/camel-case-keys.html index 549b9c97..b4ff7be7 100644 --- a/layouts/_partials/function/camel-case-keys.html +++ b/layouts/_partials/function/camel-case-keys.html @@ -26,7 +26,7 @@ // Practical usage in templates {{- $siteParams := partial "function/camel-case-keys.html" .Site.Params }} */ -}} -{{- $input := . -}} +{{- $input := . | default dict -}} {{- $output := dict -}} {{- if reflect.IsMap $input -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index fa7cc139..19a1b73f 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v1.0.0-mrn0yyrp" -}} +{{- hugo.Store.Set "version" "v1.0.0-mrn7n5sf" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}}