Skip to content

The new types in @wordpress/blocks don't have the generics that the @types/wordpress__blocks package did #77390

@joshualip-plaudit

Description

@joshualip-plaudit

Description

The new typedefs break any code that was relying on the generics the old DefinitelyTyped defs used to handle typing the attributes passed to edit and save.

I'm currently putting together a PR that ports over generics for the registration functions.

Step-by-step reproduction instructions

Try to build the following:

registerBlockType(blockJson as unknown as BlockConfiguration<{ allowedBlocks?: string[], templateLock?: EditorTemplateLock }>, {
	icon: contents,
	edit({attributes: {allowedBlocks, templateLock}, clientId, isSelected}) {
		return <>
			<InsertSiblingOrChildBlockShortcut clientId={clientId} targetBlockName="plaudit-accordion-block/accordion" addedBlockName="plaudit-accordion-block/item" isSelected={isSelected} />
			<div
				{...useInnerBlocksProps(useBlockProps(), {
					allowedBlocks,
					template: [['core/paragraph', {}]],
					templateLock,
				})}
			/>
		</>;
	},
	save() {
		return <div {...useInnerBlocksProps.save(useBlockProps.save())} />;
	}
});

Previously, allowedBlocks and templateLock would have been properly typed as string[]|undefined and EditorTemplateLock|undefined respectively. This is no longer the case because the registerBlockType function is missing the generic that links up the types.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Labels

[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions