Type definitions for wp object in custom block

Created on 23 May 2024, about 1 month ago
Updated 27 May 2024, about 1 month ago

When developing a custom block is there a way to pull in the wp type definitions so that VS Code (or whatever editor you use) can be intelligent and show you suggestions? The example block has this first line:

const { blocks, data, element, components, blockEditor } = wp;

VS Code does not know anything about the wp variable and has no way to help the developer understand what that object contains. For example, when adding a wp.blockEditor.RichText element how do you know, from your editor, what fields RichText has available?

Viewing the window.wp is helpful but not a great long term solution.

We can use import { RichText } from '@wordpress/rich-text'; to pull in the different wordpress modules just for development but thats yucky. You would have to add those imports just for code writing and then comment them out each time you want to build.

I have not seen anyone mention this so perhaps I'm doing something wrong?

✨ Feature request
Status

Closed: works as designed

Version

2.8

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jlain

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024