I would like to do the following. But it seems I cannot type the function parameter with one of the variant option. What would be the proper way to achieve this in rescript?
type subject = Math | History
type person =
| Teacher({firstName: string, subject: subject})
| Student({firstName: string})
let hasSameNameThanTeacher = (
~teacher: Teacher, // syntax error here
~student: Person,
) => {
teacher.firstName == student.firstName
}
Teacher
andStudent
are not types themselves, but constructors that construct values of typeperson
. If you want them to have distinct types you have to make it explicit: