Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable autocompletion for core-data store across the board #42233

Closed
Closed
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
6 changes: 6 additions & 0 deletions packages/block-editor/src/wordpress.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module '@wordpress/data' {
export * from '@wordpress/data/build-types/index';
}
declare module '@wordpress/core-data' {
export * from '@wordpress/core-data/build-types/index';
}
1 change: 1 addition & 0 deletions packages/block-editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"declarationDir": "build-types"
},
"references": [
{ "path": "../core-data" },
{ "path": "../deprecated" },
{ "path": "../element" },
{ "path": "../hooks" },
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/src/entity-types/nav-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { Context, ContextualField, OmitNevers } from './helpers';

import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';
import { DefaultContextOf } from './index';
import type { DefaultContextOf } from './index';

declare module './base-entity-records' {
export namespace BaseEntityRecords {
Expand Down
11 changes: 6 additions & 5 deletions packages/core-data/src/hooks/use-query-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ interface QuerySelectResponse< Data > {
*
* @return {QuerySelectResponse} Queried data.
*/
export default function __experimentalUseQuerySelect( mapQuerySelect, deps ) {
return useSelect( ( select, registry ) => {
const resolve = ( store ) => enrichSelectors( select( store ) );
return mapQuerySelect( resolve, registry );
}, deps );
export default function __experimentalUseQuerySelect(mapQuerySelect, deps) {
const callback = ((select, registry) => {
const resolve = (store) => enrichSelectors(select(store));
return mapQuerySelect(resolve, registry);
}) as any;
return useSelect( callback , deps );
}

interface EnrichedSelectors {
Expand Down
2 changes: 0 additions & 2 deletions packages/core-data/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ const storeConfig = () => ( {
* Store definition for the code data namespace.
*
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
*
* @type {Object}
*/
export const store = createReduxStore( STORE_NAME, storeConfig() );

Expand Down
6 changes: 3 additions & 3 deletions packages/core-data/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type {
// It makes the selectors slightly more safe, but is intended to evolve
// into a more detailed representation over time.
// See https://github.com/WordPress/gutenberg/pull/40025#discussion_r865410589 for more context.
interface State {
export interface State {
autosaves: Record< string | number, Array< unknown > >;
blockPatterns: Array< unknown >;
blockPatternCategories: Array< unknown >;
Expand Down Expand Up @@ -259,7 +259,7 @@ export function getEntityConfig( state: State, kind: Kind, name: Name ): any {
* ? EntityRecordOf< K, N, C >
* : Partial< EntityRecordOf< K, N, C > >
*/
interface GetEntityRecord {
export interface GetEntityRecord {
<
R extends EntityRecordOf< K, N >,
C extends Context = DefaultContextOf< R >,
Expand Down Expand Up @@ -494,7 +494,7 @@ export function hasEntityRecords<
* ? EntityRecordOf< K, N, C >[]
* : Partial< EntityRecordOf< K, N, C > >[]
*/
interface GetEntityRecords {
export interface GetEntityRecords {
<
R extends EntityRecordOf< K, N >,
C extends Context = DefaultContextOf< R >,
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions packages/core-data/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"noUnusedParameters": false,
"noImplicitAny": false,
"checkJs": false
},
"references": [
{ "path": "../data" },
{ "path": "../api-fetch" }
],
"include": [
"src/**/*.js",
"src/**/*.ts",
]
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{ "path": "packages/block-editor" },
{ "path": "packages/components" },
{ "path": "packages/compose" },
{ "path": "packages/core-data" },
{ "path": "packages/data" },
{ "path": "packages/date" },
{ "path": "packages/deprecated" },
Expand Down
3 changes: 3 additions & 0 deletions typings/wordpress.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module '@wordpress/data' {
export * from '@wordpress/data/build-types/index';
}