【发布时间】:2023-02-10 11:12:29
【问题描述】:
我正在尝试在 wordpress 和古腾堡编辑器的开发中使用打字稿。我正在尝试使用 useSelect() 挂钩,但在尝试使用 core/editor 的附加函数时出现类型错误。所以这是我遇到的问题的一个例子:
const featured = useSelect(
(select) =>
select('core/editor').getEditedPostAttribute('meta')[
'_projects_featured'
],
[]
)
我收到以下错误:
“从不”类型上不存在属性“getEditedPostAttribute”。
我假设是因为没有应用正确的类型,因为无论我尝试从
select('core/editor')获得什么,我都会得到同样的错误。但我不确定我应该应用哪种类型。我可以将选定的core/editor设置为any,例如:const editor: any = useSelect((select) => select('core/editor')) const postAttribute = editor.getEditedPostAttribute()但这显然违背了使用 typescript 的目的。
关于使用 wordpress 和 typescript 进行开发的信息并不多,也没有官方的 Wordpress typescript 文档。我添加了一堆打字,我将从我的
package.json发布其中的一些。"dependencies": { "@types/wordpress__components": "^19.10.5", "@types/wordpress__core-data": "^2.4.5", "@types/wordpress__data": "^6.0.1", "@types/wordpress__edit-post": "^4.0.1", "@types/wordpress__editor": "^11.0.0", "@types/wordpress__element": "^2.14.1", "@types/wordpress__plugins": "^3.0.0", "@wordpress/data": "^8.0.0", "@wordpress/edit-post": "^7.0.0", "@wordpress/plugins": "^5.0.0" }任何帮助,将不胜感激。我不确定在 Wordpress Gutenberg 中使用 typescript 进行开发是否是个好主意。
【问题讨论】:
标签: reactjs typescript wordpress wordpress-gutenberg