`hexo.theme.config` property should not be of type `object`
zkz098 opened this issue · comments
Check List
- I have already read Docs page & Troubleshooting page.
- I have already searched existing issues and they are not help to me.
- I examined error or warning messages and it's difficult to solve.
- I am using the latest version of Hexo. (run
hexo version
to check) - My Node.js is matched the required version.
Expected behavior
The hexo.theme.config
should be of type any
or another type that allows access to unknown properties. For example, the following line of code works well on Hexo 7.0.0:
const VendorsCfg = hexo.theme.config.vendors as VendorsConfig;
Actual behavior
But in Hexo 7.1.0, this code cannot pass TypeScript compilation because hexo.theme.config
is of type object
, and this type does not allow access to unknown properties. When compiling the above code with Hexo 7.1.0, the result is:
Error: utils.ts(24,40): error TS2339: Property 'vendors' does not exist on type 'object'.
If I want to make it compile in Hexo 7.1.0, I have to use the following code snippet:
const VendorsCfg = (hexo.theme.config as any).vendors as VendorsConfig;
How to reproduce?
Accessing any custom property of hexo.theme.config
in TypeScript.
Is the problem still there under Safe mode
?
This issue occurs in the development environment and is unrelated to Safe Mode.
Your Node.js & npm version
v20.11.0
10.2.4
Your Hexo and Plugin version
This issue occurs in the development environment, so I am unable to provide specific details for this item.
Your package.json
I provide the `package.json` for this development environment as the content for this item:
{
"name": "hexo-theme-shokax",
"version": "0.3.12",
"description": "a hexo theme based on shoka",
"main": "index.js",
"repository": "https://github.com/theme-shoka-x/hexo-theme-shokaX",
"author": "zkz098",
"license": "AGPL-3.0-or-later",
"scripts": {
"test": "tsc --build --verbose",
"build": "cd ./source && tsc --build --verbose && cd ../scripts && tsc --build --verbose"
},
"devDependencies": {
"@types/fancybox": "^3.5.6",
"@types/jquery": "^3.5.29",
"@types/js-yaml": "^4.0.9",
"@types/lozad": "^1.16.4",
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint": "^8.56.0",
"eslint-config-standard": "~17",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-vue": "^9.20.1",
"instantsearch.js": "^4.64.0",
"typescript": "^5.3.3",
"vue": "^3.4.15"
},
"dependencies": {
"esbuild": "^0.19.11",
"hexo": "^7.0.0",
"hexo-fs": "^4.1.1",
"hexo-pagination": "^3.0.0",
"hexo-util": "^3.2.0",
"js-yaml": "^4.1.0",
"lozad": "^1.16.0",
"mouse-firework": "^0.0.4",
"theme-shokax-anime": "^0.0.6",
"theme-shokax-pjax": "^0.0.3"
},
"engines": {
"node": ">=18.0.0"
},
"engineStrict": true
}
Your site's _config.yml
(Optional)
No response
Others
No response