Skip to content

Commit

Permalink
- Corrected type inference.
Browse files Browse the repository at this point in the history
- Typescript updated.
  • Loading branch information
OliMe committed Mar 25, 2024
1 parent 6d6e4fb commit 39b3d86
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"eslint-plugin-standard": "^4.0.0",
"jest": "^26.6.3",
"prettier": "^2.6.2",
"typescript": "^4.5.5"
"typescript": "^5.4.3"
},
"repository": {
"type": "git",
Expand Down
11 changes: 9 additions & 2 deletions src/toolkit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
PrepareMessage,
MessageCreator,
CreatorReturnType,
ExtendedMessageWithoutPayload,
ExtendedMessageWithPayload,
} from './types';
import { useCache } from './cache';

Expand Down Expand Up @@ -170,7 +172,7 @@ export function createCommand(
function createMessage<
TPayload,
TResponse,
TAdditionalProps,
TAdditionalProps extends { [key: string]: any } | undefined,
TPrepare extends PrepareMessage<TAdditionalProps> | undefined = undefined,
>(
messageType: string,
Expand All @@ -183,7 +185,12 @@ function createMessage<
type: messageType,
payload,
channelType,
} as CreatorReturnType<TAdditionalProps, ExtendedMessage<TPayload, TResponse>>;
} as CreatorReturnType<
TAdditionalProps,
TPayload extends undefined
? ExtendedMessageWithoutPayload<TResponse>
: ExtendedMessageWithPayload<TPayload, TResponse>
>;
};
creator.type = messageType;
creator.channelType = channelType;
Expand Down
7 changes: 6 additions & 1 deletion src/toolkit/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export interface MessageCreator<
TResponse,
TAdditionalProps extends { [key: string]: any } | undefined,
> {
(payload: TPayload): CreatorReturnType<TAdditionalProps, ExtendedMessage<TPayload, TResponse>>;
(payload: TPayload): CreatorReturnType<
TAdditionalProps,
TPayload extends undefined
? ExtendedMessageWithoutPayload<TResponse>
: ExtendedMessageWithPayload<TPayload, TResponse>
>;
type: string;
channelType: ChannelSegregation;
toString: () => string;
Expand Down

0 comments on commit 39b3d86

Please sign in to comment.