From 752499fa99287b887f30c1df9875c766d9529765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 17 Mar 2022 15:20:40 +0100 Subject: [PATCH] Turn entities.js into a Typescript file with the minimal changes required to avoid type errors --- packages/core-data/src/{entities.js => entities.ts} | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) rename packages/core-data/src/{entities.js => entities.ts} (95%) diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.ts similarity index 95% rename from packages/core-data/src/entities.js rename to packages/core-data/src/entities.ts index 09731d54841fc2..dd4dfbae96fee7 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.ts @@ -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'; @@ -190,7 +191,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. @@ -218,7 +219,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 @@ -252,9 +255,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 {