Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions types/wordpress__blocks/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import { IconType } from "@wordpress/components";
import { StoreDescriptor } from "@wordpress/data";
import { ReduxStoreConfig, StoreDescriptor } from "@wordpress/data";
import { ShortcodeMatch } from "@wordpress/shortcode";
import { ComponentType, ReactElement } from "react";

export * from "./api";
export { withBlockContentContext } from "./block-content-provider";

declare module "@wordpress/data" {
/**
* @deprecated Use the version that takes a store descriptor object instead
*/
function dispatch(key: "core/blocks"): typeof import("./store/actions");
/**
* @deprecated Use the version that takes a store descriptor object instead
*/
function select(key: "core/blocks"): typeof import("./store/selectors");
}

export interface BlocksStoreDescriptor extends StoreDescriptor {
type Decurry<S extends { [key: string]: (...args: any[]) => any }> = {
[key in keyof S]: (state: any, ...args: Parameters<S[key]>) => ReturnType<S[key]>;
};
export interface BlocksStoreDescriptor extends
StoreDescriptor<
ReduxStoreConfig<any, typeof import("./store/actions"), Decurry<typeof import("./store/selectors")>>
>
{
name: "core/blocks";
}

Expand Down
25 changes: 25 additions & 0 deletions types/wordpress__blocks/wordpress__blocks-tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -721,3 +721,28 @@ dispatch("core/blocks").addBlockStyles("my/foo", { name: "foo__bar", label: "Foo

// $ExpectType void
dispatch("core/blocks").setDefaultBlockName("my/foo");

//
// store objects
// ----------------------------------------------------------------------------

// $ExpectType readonly BlockStyle[] | undefined
select(blocks.store).getBlockStyles("my/foo");

// $ExpectType string | undefined
select(blocks.store).getFreeformFallbackBlockName();

// $ExpectType string | undefined
select(blocks.store).getUnregisteredFallbackBlockName();

// $ExpectType boolean
select(blocks.store).isMatchingSearchTerm("my/foo", "foo");

// $ExpectType boolean
select(blocks.store).isMatchingSearchTerm(BLOCK, "foo");

// $ExpectType Promise<void>
dispatch(blocks.store).addBlockStyles("my/foo", { name: "foo__bar", label: "Foobar" });

// $ExpectType Promise<void>
dispatch(blocks.store).setDefaultBlockName("my/foo");