type TMakeEmberPostMessageParams<dataT> = {
type: string,
data: unknown,
mockSource?: (type: string, data: unknown) => (Promise<dataT> | dataT),
defaultDelay?: number,
settingName?: string,
requestId?: string | number,
};
type TMakeEmberPostMessage<dataT> = (
type: TMakeEmberPostMessageParams<dataT>['type'],
data: TMakeEmberPostMessageParams<dataT>['data'],
mockSource?: TMakeEmberPostMessageParams<dataT>['mockSource'],
defaultDelay?: TMakeEmberPostMessageParams<dataT>['defaultDelay'],
settingName?: TMakeEmberPostMessageParams<dataT>['settingName'],
requestId?: TMakeEmberPostMessageParams<dataT>['requestId'],
) => Promise<dataT>;
Is there a way to generate the args type for TMakeEmberPostMessage from TMakeEmberPostMessageParams, without specifying each argument types? That means converting the object type into multiple function argument types.
I can't change TMakeEmberPostMessage params to a single object as it's used in different codebases.
The problem is there are a few functions that are object params, and would like to Pick couple of properties from TMakeEmberPostMessageParams
Like I would like to do,
type TGetEmberUrlParams<dataT = unknown> = {
route?: string,
params?: Record<string, unknown>,
queryParams?: Record<string, unknown>,
emberMainDomain?: boolean,
returnUrl?: boolean,
openInNewTab?: boolean,
} & Pick<TMakeEmberPostMessageParams<dataT>, 'type' | 'mockSource' | 'defaultDelay' | 'settingName'>;
makeEmberPostMessagefunction which is type of TMakeEmberPostMessage, and I don't want to duplicate the object type there, so I would like to create one object type and use it in this function and other functions with objects can use it as well(...args: TheTupleType)in the function parameter list. But see the linked answers for why that's a really, really bad idea. :-) As soon as you can feasibly schedule it, I'd schedule the few hours needed to update the calls to the function so you can pass an object instead.Pickfor a few properties as shown in the updated question from the tuple type, so is it better instead to duplicate the type or keep it with what I've right now?TMakeEmberPostMessageParams. That seems just fine as it is (temporarily, until you can update the function to accept an object).