-
Notifications
You must be signed in to change notification settings - Fork 666
Closed
Labels
Milestone
Description
Current TS definitions show error for the following usages:
import { isEqual } from 'lodash'
interface Transaction {
transactionId: string
}
const toId = (transaction: Transaction) => transaction.transactionId
const transactionsIds = (transactions: Transaction[]) => transactions.map(toId)
const collectionsEqual = (ts1: Transaction[], ts2: Transaction[]) => isEqual(transactionsIds(ts1), transactionsIds(ts2))
const createTransactionsSelector = createSelectorCreator(defaultMemoize, collectionsEqual)Results in:
Error:(148, 58) TS2345: Argument of type '<F extends Function>(func: F, equalityCheck?: (<T>(a: T, b: T, index: number) => boolean) | undefined) => F' is not assignable to parameter of type '<F extends Function>(func: F, option1: ((ts1: Transaction[], ts2: Transaction[]) => boolean) | undefined) => F'.
Types of parameters 'equalityCheck' and 'option1' are incompatible.
Types of parameters 'ts1' and 'a' are incompatible.
Type 'T' is not assignable to type 'Transaction[]'.
This also happens when creating memoized function:
const groupTransactionsByLabel = defaultMemoize(
(transactions: Transaction[]) => groupBy(transactions, headerForTransaction),
collectionsEqual,
)Possible solution:
When I change:
export function defaultMemoize<F extends Function>(
func: F, equalityCheck?: <T>(a: T, b: T, index: number) => boolean,
): F;to:
export function defaultMemoize<F extends Function, T>(
func: F, equalityCheck?: (a: T, b: T, index: number) => boolean,
): F;Everything works as expected but I'm not sure if that's correct approach.
SamChou19815, markov00, erparks, martinschnurer, danielcorreia and 11 more