From 1d45fbb2a4a51b288fb278edeec1bfb22234cdc1 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Mon, 5 Feb 2024 19:33:07 +0100 Subject: [PATCH] Fix more TS warnings --- packages/ra-core/src/core/useResourceDefinitions.ts | 5 +++-- packages/ra-core/src/dataProvider/fetch.ts | 2 +- packages/ra-core/src/form/useUnique.ts | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/ra-core/src/core/useResourceDefinitions.ts b/packages/ra-core/src/core/useResourceDefinitions.ts index c7c8c2d46dc..9846703fc72 100644 --- a/packages/ra-core/src/core/useResourceDefinitions.ts +++ b/packages/ra-core/src/core/useResourceDefinitions.ts @@ -1,4 +1,5 @@ -import { ResourceDefinitions } from './ResourceDefinitionContext'; +import type { ResourceOptions } from '../types'; +import type { ResourceDefinitions } from './ResourceDefinitionContext'; import { useResourceDefinitionContext } from './useResourceDefinitionContext'; /** @@ -20,6 +21,6 @@ import { useResourceDefinitionContext } from './useResourceDefinitionContext'; * // } */ export const useResourceDefinitions = < - OptionsType = any + OptionsType extends ResourceOptions = any >(): ResourceDefinitions => useResourceDefinitionContext().definitions; diff --git a/packages/ra-core/src/dataProvider/fetch.ts b/packages/ra-core/src/dataProvider/fetch.ts index 9a7c7b47466..9bd5cb74708 100644 --- a/packages/ra-core/src/dataProvider/fetch.ts +++ b/packages/ra-core/src/dataProvider/fetch.ts @@ -95,7 +95,7 @@ const isValidObject = value => { return !isArray && !isBuffer && isObject && hasKeys; }; -export const flattenObject = (value, path = []) => { +export const flattenObject = (value: any, path: string[] = []) => { if (isValidObject(value)) { return Object.assign( {}, diff --git a/packages/ra-core/src/form/useUnique.ts b/packages/ra-core/src/form/useUnique.ts index 221a41c3059..e48ec5ac1ca 100644 --- a/packages/ra-core/src/form/useUnique.ts +++ b/packages/ra-core/src/form/useUnique.ts @@ -106,7 +106,11 @@ export const useUnique = (options?: UseUniqueOptions) => { } ); - if (total > 0 && !data.some(r => r.id === record?.id)) { + if ( + typeof total !== 'undefined' && + total > 0 && + !data.some(r => r.id === record?.id) + ) { return { message, args: {