Skip to content

Commit

Permalink
Update @wordpress/blocks types and remove expected error
Browse files Browse the repository at this point in the history
  • Loading branch information
chriszarate committed Dec 3, 2024
1 parent d8506df commit 4a434c9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 42 deletions.
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@testing-library/jest-dom": "6.6.3",
"@testing-library/react": "16.0.1",
"@types/wordpress__block-editor": "11.5.15",
"@types/wordpress__blocks": "12.5.15",
"@types/wordpress__editor": "14.3.1",
"@vitest/coverage-v8": "2.1.2",
"@wordpress/api-fetch": "7.10.0",
Expand Down
3 changes: 1 addition & 2 deletions src/blocks/remote-data-container/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { registerBlockType } from '@wordpress/blocks';
import { registerBlockBindingsSource, registerBlockType } from '@wordpress/blocks';
import { addFilter } from '@wordpress/hooks';
import { registerFormatType } from '@wordpress/rich-text';

Expand All @@ -8,7 +8,6 @@ import { Edit } from '@/blocks/remote-data-container/edit';
import { addUsesContext } from '@/blocks/remote-data-container/filters/addUsesContext';
import { withBlockBindingShim } from '@/blocks/remote-data-container/filters/withBlockBinding';
import { Save } from '@/blocks/remote-data-container/save';
import { registerBlockBindingsSource } from '@/types/expected-errors/registerBlockBindingsSource';
import { getBlocksConfig } from '@/utils/localized-block-data';
import './style.scss';

Expand Down
36 changes: 0 additions & 36 deletions src/types/expected-errors/registerBlockBindingsSource.ts

This file was deleted.

32 changes: 31 additions & 1 deletion types/wordpress__blocks/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
import { BlockEditProps as BlockEditPropsOriginal } from '@wordpress/blocks';
import type { BlockEditProps as BlockEditPropsOriginal } from '@wordpress/blocks';
import type {
BlockEditorStoreActions,
BlockEditorStoreSelectors,
BlockEditorStoreDescriptor,
} from '@wordpress/block-editor';

/**
* The types provided by @wordpress/blocks are incomplete.
*/

interface GetValuesPayload< Context, Values > {
bindings: Values;
clientId: string;
context: Context;
select: ( store: BlockEditorStoreDescriptor ) => BlockEditorStoreSelectors;
}

interface SetValuesPayload< Context, Values > extends GetValuesPayload< Context, Values > {
dispatch: ( store: BlockEditorStoreDescriptor ) => BlockEditorStoreActions;
values: Values;
}

declare module '@wordpress/blocks' {
interface BlockEditProps< T extends Record< string, any > > extends BlockEditPropsOriginal< T > {
name: string;
}

interface BlockBindingsSource< Context = Record< string, unknown >, Values = unknown > {
canUserEditValue?: ( payload: GetValuesPayload< Context, Values > ) => boolean;
getValues?: ( payload: GetValuesPayload< Context, Values > ) => Values;
label?: string;
name: string;
setValues?: ( payload: SetValuesPayload< Context, Values > ) => void;
usesContext?: string[];
}

function registerBlockBindingsSource< Context, Values >(
source: BlockBindingsSource< Context, Values >
): void;
}

0 comments on commit 4a434c9

Please sign in to comment.