diff --git a/package-lock.json b/package-lock.json index c7a9f13..eaea701 100644 --- a/package-lock.json +++ b/package-lock.json @@ -39,7 +39,7 @@ "eslint-plugin-standard": "^4.0.0", "jest": "^26.6.3", "prettier": "^2.6.2", - "typescript": "^4.5.5" + "typescript": "^5.4.3" } }, "node_modules/@ampproject/remapping": { @@ -12995,16 +12995,16 @@ } }, "node_modules/typescript": { - "version": "4.5.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz", - "integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==", + "version": "5.4.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz", + "integrity": "sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==", "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=14.17" } }, "node_modules/unbox-primitive": { @@ -23424,9 +23424,9 @@ } }, "typescript": { - "version": "4.5.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz", - "integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==", + "version": "5.4.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz", + "integrity": "sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==", "dev": true }, "unbox-primitive": { diff --git a/package.json b/package.json index 84128e2..9446e93 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/toolkit/index.ts b/src/toolkit/index.ts index 0aed19d..c116973 100644 --- a/src/toolkit/index.ts +++ b/src/toolkit/index.ts @@ -10,6 +10,8 @@ import { PrepareMessage, MessageCreator, CreatorReturnType, + ExtendedMessageWithoutPayload, + ExtendedMessageWithPayload, } from './types'; import { useCache } from './cache'; @@ -170,7 +172,7 @@ export function createCommand( function createMessage< TPayload, TResponse, - TAdditionalProps, + TAdditionalProps extends { [key: string]: any } | undefined, TPrepare extends PrepareMessage | undefined = undefined, >( messageType: string, @@ -183,7 +185,12 @@ function createMessage< type: messageType, payload, channelType, - } as CreatorReturnType>; + } as CreatorReturnType< + TAdditionalProps, + TPayload extends undefined + ? ExtendedMessageWithoutPayload + : ExtendedMessageWithPayload + >; }; creator.type = messageType; creator.channelType = channelType; diff --git a/src/toolkit/types.ts b/src/toolkit/types.ts index 8c67ff1..4aaec1a 100644 --- a/src/toolkit/types.ts +++ b/src/toolkit/types.ts @@ -45,7 +45,12 @@ export interface MessageCreator< TResponse, TAdditionalProps extends { [key: string]: any } | undefined, > { - (payload: TPayload): CreatorReturnType>; + (payload: TPayload): CreatorReturnType< + TAdditionalProps, + TPayload extends undefined + ? ExtendedMessageWithoutPayload + : ExtendedMessageWithPayload + >; type: string; channelType: ChannelSegregation; toString: () => string;