import { pushNotifications } from '@atomic-ui/react'; import { createAppAsyncThunk }…
- User
import { pushNotifications } from '@atomic-ui/react';
import { createAppAsyncThunk } from '$ufs-common';
import { sectionEndpoints } from '../api'; import type { GetSectionArgs, Section } from './types';
export const [useGetSection, getSection] = createAppAsyncThunk< Promise<Section | null>, GetSectionArgs
('documentController/getSection', async (params, { dispatch }) => { try { const { body } = await dispatch( sectionEndpoints.getSection.initiate(params, { forceRefetch: true }), ).unwrap();
return body; } catch (error) { pushNotifications.push({ message: 'Произошла ошибка при загрузке секции', variant: 'negative', }); return null; }}); how add generic to Section in type here
- Assistant
You can add a generic type parameter to the
Sectiontype by defining it in theGetSectionArgstype. Here is an example of how you can add a generic type parameter to theSectiontype in theGetSectionArgstype:import { pushNotifications } from '@atomic-ui/react'; import { createAppAsyncThunk } from '$ufs-common'; import { sectionEndpoints } from '../api'; import type { GetSectionArgs, Section } from './types'; // Define a generic type parameter T for Section type GetSectionArgs<T> = { id: string; // Other properties specific to the GetSectionArgs type }; export const [useGetSection, getSection] = createAppAsyncThunk< Promise<Section<T> | null>, GetSectionArgs<T> >('documentController/getSection', async (params, { dispatch }) => { try { const { body } = await dispatch( sectionEndpoints.getSection.initiate(params, { forceRefetch: true }), ).unwrap(); return body; } catch (error) { pushNotifications.push({ message: 'Произошла ошибка при загрузке секции', variant: 'negative', }); return null; } }); - User
its doesnt works
- Assistant
I apologize for the confusion. It seems I made an error in my previous response. If you want to add a generic type parameter to the
Sectiontype, you should define the generic type parameter directly in theSectiontype definition. Here's how you can do it:import { pushNotifications } from '@atomic-ui/react'; import { createAppAsyncThunk } from '$ufs-common'; import { sectionEndpoints } from '../api'; import type { GetSectionArgs } from './types'; // Define a generic type parameter T for Section type Section<T> = { // Define properties for Section with generic type T }; export const [useGetSection, getSection] = createAppAsyncThunk< Promise<Section<any> | null>, GetSectionArgs >('documentController/getSection', async (params, { dispatch }) => { try { const { body } = await dispatch( sectionEndpoints.getSection.initiate(params, { forceRefetch: true }), ).unwrap(); return body; } catch (error) { pushNotifications.push({ message: 'Произошла ошибка при загрузке секции', variant: 'negative', }); return null; } });