new Error('Missing "msgType" property'); } if (typeof message.fromUser !== 'string') { throw new Error('Missing "fromUser" property'); } // … more checks // … send message to server }
}; let me = {name: "Rafa", age: 29}; print_string me.name; me.age = me.age + 1; (* not possible to modify fields unless marked as `mutable` *) me.name = "Bob";
}; let me = {name: "Rafa", age: 29}; print_string me.name; me.age = me.age + 1; (* not possible to modify fields unless marked as `mutable` *) me.name = "Bob"; Error: The record field name is not mutable
=> { switch colorNum { | 0 => "black" | 1 => "white" }; }; Warning 8: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: 2
Director; let person1 = Teacher; let getProfession person => switch person { | Teacher => "A teacher" | Director => "A director" }; }; let profession = School.getProfession School.person1;
typically compiles to module FileA below */ let a = 1; let b = 2; /* fileB.re */ /* You can access module FileA from any other module on your system */ let result = FileA.a + FileA.b;
| Gift {src} | Image {src} => Some src | Plain _ => None }; /* … */ /* … */ type video = { src: string, duration: int }; type messageContent = | Plain plain | Image image | Gift gift | Video video; Warning 8: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: Video _
and ecosystem. • Understand the problems you are trying to solve • Understand cost you are going to pay. • Seek support among your team. • Be prepared for the issues you’ll face. • Be responsible. Don’t rewrite. JS interop is #