Search for a keyword across post types in a Gutenberg component

I’m answering myself for the benefit of others. I was passing an array of post type slugs to apiFetch instead of passing an array with their rest_base parameter. So, the correct function should be:

const postTypes = useSelect( ( select ) => {
    const { getPostTypes } = select( 'core' );
    const excludedPostTypes = [ 'attachment' ];
    const filteredPostTypes = getPostTypes( { per_page: -1 } )?.filter(
        ( { viewable, slug } ) => viewable && ! excludedPostTypes.includes( slug )
    );
    const result = ( filteredPostTypes || [] ).map( ( { rest_base } ) => rest_base );
    return result;
}, [] );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)