問題があります。Typescript Type 'string'はtype(enum)に割り当てられません
、列挙型の属性に列挙値を割り当てるエラー取得中:私は取得するべきではないと仮定Type 'string' is not assignable to type 'CountryCode'.
は、属性と値の両方が同じenum
タイプある原因を
enum
属性を持つサービス:
@Injectable()
export class UserData {
private _country_code: CountryCode;
private _currency_code: CurrencyCode;
constructor() { }
get country_code(): CountryCode {
return this._country_code;
}
set country_code(value: CountryCode) {
this._country_code = value;
}
get currency_code(): CurrencyCode {
return this._currency_code;
}
set currency_code(value: CurrencyCode) {
this._currency_code = value;
}
}
列挙
エラーとの利用ケース:
this.userData.country_code = CountryCode[data.country_code];