Escape reserved keywords for fields in Motoko

50 Views Asked by At

How is a field name that is a reserved keyword able to be 'escaped' to be used in a type?

type User = {
    type: Text; // `type` cant be used since its reserved
};

I want to be able to return data with a field name of type.

Is there a character prefix or something so that when it serialized in a request it outputs 'type'?

Either that or some sort of serialization decoration for the field to specify 'type'

1

There are 1 best solutions below

0
On

From the docs: If the field name is a reserved name in Motoko, an undescore is appended. So record { if : bool } corresponds to { if_ : Bool }.