Skip to content

Commit

Permalink
Use better approach for picking anchor button types
Browse files Browse the repository at this point in the history
  • Loading branch information
noahtallen committed Jul 19, 2023
1 parent e5d7b63 commit a5014ec
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions client/blocks/reader-export-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button } from '@wordpress/components';
import { useI18n } from '@wordpress/react-i18n';
import { saveAs } from 'browser-filesaver';
import { useTranslate } from 'i18n-calypso';
import { useState, useEffect, useRef, useCallback, ComponentProps } from 'react';
import { useState, useEffect, useRef, useCallback, ComponentPropsWithoutRef } from 'react';
import {
READER_EXPORT_TYPE_SUBSCRIPTIONS,
READER_EXPORT_TYPE_LIST,
Expand All @@ -27,12 +27,9 @@ type ReaderExportButtonProps = {
listId?: number;
};

// Note: there is a type issue where `disabled` can't be used if we accept every single
// button prop. As a result, we can pick the props we want to allow.
type AcceptedButtonProps = Pick<
ComponentProps< typeof Button >,
'icon' | 'iconSize' | 'variant' | 'disabled'
>;
// Note: since the Button must be disableable, it must not be a link. So we need to remove the link type variant from the accepted props.
type RemoveAnchorButtonProps< T > = T extends { href: string } ? never : T;
type AcceptedButtonProps = RemoveAnchorButtonProps< ComponentPropsWithoutRef< typeof Button > >;

const ReaderExportButton = ( {
filename = 'reader-export.opml',
Expand Down

0 comments on commit a5014ec

Please sign in to comment.