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

Migrate entities.js to Typescript #39547

Merged
merged 1 commit into from
Apr 2, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import { addEntities } from './actions';
import type { Post, Taxonomy, Type, Updatable } from './entity-types';

export const DEFAULT_ENTITY_KEY = 'id';

Expand Down Expand Up @@ -191,7 +192,7 @@ export const additionalEntityConfigLoaders = [
* @return {Object} Updated edits.
*/
export const prePersistPostType = ( persistedRecord, edits ) => {
const newEdits = {};
const newEdits = {} as Partial< Updatable< Post< 'edit' > > >;

if ( persistedRecord?.status === 'auto-draft' ) {
// Saving an auto-draft should create a draft by default.
Expand Down Expand Up @@ -219,7 +220,9 @@ export const prePersistPostType = ( persistedRecord, edits ) => {
* @return {Promise} Entities promise
*/
async function loadPostTypeEntities() {
const postTypes = await apiFetch( { path: '/wp/v2/types?context=view' } );
const postTypes = ( await apiFetch( {
path: '/wp/v2/types?context=view',
} ) ) as Record< string, Type< 'view' > >;
return map( postTypes, ( postType, name ) => {
const isTemplate = [ 'wp_template', 'wp_template_part' ].includes(
name
Expand Down Expand Up @@ -253,9 +256,9 @@ async function loadPostTypeEntities() {
* @return {Promise} Entities promise
*/
async function loadTaxonomyEntities() {
const taxonomies = await apiFetch( {
const taxonomies = ( await apiFetch( {
path: '/wp/v2/taxonomies?context=view',
} );
} ) ) as Record< string, Taxonomy< 'view' > >;
return map( taxonomies, ( taxonomy, name ) => {
const namespace = taxonomy?.rest_namespace ?? 'wp/v2';
return {
Expand Down