4 ms·
If you use simple data structures without logic, it is basically what he is saying. Basically `createAuthorData` is a data structure constructor. There are some
by odshoifsdhfs 6y ago
If you use simple data structures without logic, it is basically what he is saying. Basically `createAuthorData` is a data structure constructor. There are some advantages by using _.pick or something in JS land, but these don't work for other more strictly typed languages.
Also, I would be careful with using it so much as his example:
```
function createAuthorData(firstName, lastName, books) {
return {firstName: firstName, lastName: lastName, books: books};
}
function fullName(data) {
return data.firstName + " " + data.lastName;
}
function createArtistData(firstName, lastName, genre) {
return {firstName: firstName, lastName: lastName, genre: genre};
}
```
you can also do `fullName({firstName: 'Elmond', not:'really'})` and have an hard to catch bug (where an actual typesystem would catch it).
You can either use a Protocol for this (PersonName) or a base class (though those are going out of fashion nowadays)
- pjmlp 6y agoOr when structure typing is available, type example = { firstName : string; lastName : string};; let name x = x.firstName;; name {firstName = "Joe"; lastName = "User"};; Or to make it more specific let name { firstName : string} = firstName;;