I use ng-swagger-gen to generate classes, methods, etc... using swagger generated by my back end.
for this request:
consoleUsercashOutUsingPOST(consoleUserTransactionDto: ConsoleUserTransactionDto): __Observable<ConsoleUserTransaction> {
return this.consoleUsercashOutUsingPOSTResponse(consoleUserTransactionDto).pipe(
__map(_r => _r.body as ConsoleUserTransaction)
);
}
swagger-gen generated this interface param:
/* tslint:disable */
export interface ConsoleUserTransactionDto {
action?: 'COMPANY_ACTIVATION' | 'IN_APP_PURCHASE' | 'APP_PURCHASE' | 'MUSIC_PURCHASE' | 'EBOOK_PURCHASE' | 'USER_DOWNLOAD_APP';
amount?: number;
companyUuid?: number;
consoleUserUuid?: string;
isCashIn?: boolean;
mobileMoneyServiceCode?: string;
phoneNumber?: string;}
To call the method, i use it like this:
// Initialise cash out transaction
const consoleUserTransactionDto = {phoneNumber: this.cashOutPhoneNumberModel, consoleUserUuid: consoleUserId,
companyUuid: companyUid, amount: amountToPay,
mobileMoneyServiceCode: mobileMoney, isCashIn: false, action: CompanyAction.COMPANY_ACTIVATION};
// Start cash out
await this.consoleUserTransactionService.consoleUsercashOutUsingPOST(consoleUserTransactionDto).toPromise().then({
})
But I got the error
Argument of type '{ phoneNumber: string; consoleUserUuid: string; companyUuid: number; amount: number; mobileMoneyServiceCode: any; i
sCashIn: boolean; action: CompanyAction; }' is not assignable to parameter of type 'ConsoleUserTransactionDto'.
Types of property 'action' are incompatible.
Type 'CompanyAction' is not assignable to type '"COMPANY_ACTIVATION" | "IN_APP_PURCHASE" | "APP_PURCHASE" | "MUSIC_PURCHASE" | "EBOOK_PURCHASE" | "USER_DOWNLOAD_APP"'.
188 await this.consoleUserTransactionService.consoleUsercashOutUsingPOST(consoleUserTransactionDto).toPromise().then(company => {
because i set action with a string action: CompanyAction.COMPANY_ACTIVATION
instead of '"COMPANY_ACTIVATION" | "IN_APP_PURCHASE" | "APP_PURCHASE" | "MUSIC_PURCHASE" | "EBOOK_PURCHASE" | "USER_DOWNLOAD_APP"'
How could I do to pass the correct enum type ?
Thanks
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…