-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve "expected error" types (#207)
* Commit registerBlockBindingsSource types to expected-errors * Remove redundant export statements * Move NullableKeys to type utils --------- Co-authored-by: Max Schmeling <max.schmeling@automattic.com>
- Loading branch information
1 parent
cb20d12
commit 07b2146
Showing
5 changed files
with
45 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// @ts-expect-error Temporary registerBlockBindingsSource type error workaround for WordPress 6.7 | ||
import { registerBlockBindingsSource as originalRegisterBlockBindingsSource } from '@wordpress/blocks'; | ||
|
||
import type { | ||
BlockEditorStoreActions, | ||
BlockEditorStoreSelectors, | ||
BlockEditorStoreDescriptor, | ||
} from '@wordpress/block-editor'; | ||
|
||
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; | ||
} | ||
|
||
export 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[]; | ||
} | ||
|
||
export function registerBlockBindingsSource< Context, Values >( | ||
source: BlockBindingsSource< Context, Values > | ||
): void { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
originalRegisterBlockBindingsSource( source ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type NullableKeys< T, K extends keyof T > = Omit< T, K > & { | ||
[ P in K ]: T[ P ] | null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters