Skip to content

Commit 0bbe476

Browse files
committed
refactor(inverter): enhance getModule method for improved type safety
- Updated the getModule method to include additional type parameters for better type inference. - Introduced ModuleData and GetModuleReturnType to enhance the handling of module data. - Added a new test case to validate the retrieval of the manual passed authorizer in mixed-typesafe tests.
1 parent 1ef8c73 commit 0bbe476

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/inverter.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import type {
1414
WorkflowIssuanceToken,
1515
WorkflowToken,
1616
MixedRequestedModules,
17+
ModuleData,
18+
GetModuleReturnType,
1719
} from '@/types'
1820

1921
// sdk utils
@@ -219,17 +221,20 @@ export class Inverter<W extends PopWalletClient | undefined = undefined> {
219221
* @param params - The parameters for the module
220222
* @returns The module
221223
*/
222-
getModule<N extends ModuleName>(
224+
getModule<
225+
N extends MD extends ModuleData ? never : ModuleName,
226+
MD extends ModuleData | undefined = undefined,
227+
>(
223228
params: Omit<
224-
GetModuleParams<N, W>,
229+
GetModuleParams<N, W, MD>,
225230
'walletClient' | 'publicClient' | 'self'
226231
>
227-
) {
232+
): GetModuleReturnType<N, W, MD> {
228233
return getModule({
229234
...params,
230235
publicClient: this.publicClient,
231236
walletClient: this.walletClient,
232237
self: this,
233-
})
238+
} as any)
234239
}
235240
}

tests/e2e/workflow/mixed-typesafe.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,13 @@ describe('#WORKFLOW', () => {
893893
})
894894
expect(workflow).toBeObject()
895895
})
896+
it('2.1 Should get the manual passed authorizer', async () => {
897+
const authorizer = sdk.getModule({
898+
address: workflow.authorizer.address,
899+
moduleData: AUT_Roles_v1,
900+
})
901+
expect(authorizer).toBeObject()
902+
})
896903
it('3. Should Have: ( fundingToken & issuanceToken: address, module, decimals, symbol )', () => {
897904
expect(workflow.fundingToken).toContainKeys([
898905
'address',

0 commit comments

Comments
 (0)