Skip to content

Latest commit

 

History

History
52 lines (39 loc) · 1.12 KB

decorator_deriving.mdx

File metadata and controls

52 lines (39 loc) · 1.12 KB
id keywords name summary category
deriving-decorator
deriving
decorator
@deriving
This is the `@deriving` decorator.
decorators

When the @deriving decorator is applied to a record type, it expands the type into a factory function plus a set of getter/setter functions for its fields.

Note that this is an outdated decorator and you may no longer need to use it. See Convert Record Type to Abstract Record for more details.

Example

<CodeTab labels={["ReScript", "JS Output"]}>

@deriving(abstract)
type person = {
  name: string,
  age: int,
  job: string,
}

let joe = person(~name="Joe", ~age=20, ~job="teacher")

let joeName = nameGet(joe)
let joeAge = ageGet(joe)
let joeJob = jobGet(joe)
var joe = {
  name: "Joe",
  age: 20,
  job: "teacher"
};

var joeName = joe.name;
var joeAge = joe.age;
var joeJob = joe.job;

References