recordType
An implementation of the Record datatype.
using
Here's a simple recordType:
// We define the record here.const friend =// You can even nest recordsconst person =// We instantiate a record here:const kurtis =// What you get is a Map containing the keys "name", "age", and "friends"console// Map {// 'name' => 'Kurtis Rainbolt-Greene',// 'age' => 27,// 'friends' => [ Map { 'id' => '2' } ] }
Here's what happens when you break the type contract:
// Using the example above...// If you provide the wrong type for a field, you get this error:const john =// Error: You provided "25" for field age, which is limited to Number// If you miss information you get this error:const kaity =// Error: You provided no value or default value for field age, which must be an Number// If you add a field not defined:const william =// Error: You provided ["allies","enemies"], but the record doesn't define those