这是我在角5中的代码:
gotToWallet(wallet) {
const { countryId = '', currencyType = '' } = wallet || {};
let walletIdentity;
switch (currencyType) {
case 'CRYPTO':
walletIdentity = 'userWalletIdentity';
break;
case 'FIAT':
walletIdentity = 'fiatWalletIdentity';
break;
case 'ERC20TOKEN':
walletIdentity = 'xbxUserWalletIdentity';
break;
}
const { currencyId = '' } = (wallet || {})[walletIdentity] || {};
this.router.navigate([`walletMgmt/wallet-details/${currencyId}/${countryId}`]);
}
运行ng build
命令时出现以下错误:
ERROR in src/app/wallet-management/wallets/wallets.component.ts(202,12): error TS2678: Type '"CRYPTO"' is not comparable to type '""'.
src/app/wallet-management/wallets/wallets.component.ts(205,12): error TS2678: Type '"FIAT"' is not comparable to type '""'.
src/app/wallet-management/wallets/wallets.component.ts(208,12): error TS2678: Type '"ERC20TOKEN"' is not comparable to type '""'.
为什么我会收到此错误?当我运行ng serve
时,代码似乎工作正常。我只是在尝试进行构建时遇到此错误。
谢谢,任何帮助将非常感谢。
switch (currencyType as any) {
由于某种原因(也许是打字稿版本?),当你从钱包中破坏currencyType: ''
时,它被编译器解释为类型'“”而不是'string'。所以任何人都会这样做