|
|
|
|
|
by renke1
1249 days ago
|
|
There was also a different proposal that allows objects to be extended: https://github.com/tc39/proposal-bind-operator Personally, I don't use classes much, but sometimes I think free functions are a little too hard to find, so I tend to experiment with the following pattern. interface User { … }
const User = {
rename(user: User, newName: string): User { … },
getDisplayName(user: User): string { … }
}
const renke: User = { … }
console.log(User.getDisplayName(renke));
Which makes finding an operation for a certain type easier to find (just write User and trigger autocomplete).The alternative is of course having renameUser (or userRename) and getUserDisplayName (or userGetDisplayname). The prefixed version would make autocomplete easier also. |
|