Closed
Description
TypeScript Version: 3.5.1
Search Terms:
Infer, Multiple, Generic
Code
type RequesterBaseType = (...args: any[]) => any;
type SuccessUnpacker<RequesterType extends RequesterBaseType, PayloadType> = (
payload: ReturnType<RequesterType>
) => PayloadType;
type ResultTracker<PayloadType> = PayloadType extends ArrayLike<infer PackedPayloadType>
? (instance: PackedPayloadType) => Partial<PackedPayloadType>
: (instance: PayloadType) => Partial<PayloadType>;
declare function createApiModule<
PayloadType,
TrackingType,
RequesterType extends RequesterBaseType = RequesterBaseType
>(
apiMethod: RequesterType,
unpackSuccess: SuccessUnpacker<RequesterType, PayloadType>,
trackResult?: ResultTracker<PayloadType>
): void;
type MyPayload = {
a: string;
}
createApiModule(
() => [{a: 'a'}] as MyPayload[],
payload => payload,
({ a }) => ({ a })
);
Expected behavior:
Allowed return type of unpackSuccess
should be as MyPayload[]
Actual behavior:
Allowed return type of unpackSuccess
is be MyPayload
.
Related Issues:
I tried to search for related issues but could not find anything, maybe I don't know the correct terminology.