I used typegen to generate my types from definitions.
Definition
Person: {
status: 'Status',
balance: 'u128',
},
Status: {
_enum: ['Active', 'Suspended', 'Deactivated'],
},
Generated types
/** @name Status */
export interface Status extends Enum {
readonly isActive: boolean;
readonly isSuspended: boolean;
readonly isDeactivated: boolean;
readonly type: 'Active' | 'Suspended' | 'Deactivated';
}
/** @name Person */
export interface Person extends Struct {
readonly status: Status;
readonly balance: u128;
}
Note that the enum
type has fields isActive
, isSuspended
, isDeactivated
.
`
Decoding my type
I created a function in my contract that returns Result<Person, Error>
I decode this result in JS.
const decoded = this.contract.api.registry.createType(`Result<Person, Error>`, result.data.toU8a(true))
if (decoded.isOk) {
return decoded.asOk.toPrimitive()
This is where my problem starts. The toPrimitive
function (and toJSON
, toHuman
, etc.) does not output the isActive
, isSuspended
, and isDeactivated
fields of my Status
enum. They are undefined
.
How do I access the isActive
, isSuspended
, and isDeactivated
fields after decoding my type?