11 likes
·
198 reads
5 comments
Interfaces are specific and explicit to OOP.
Are you serious?
Thanks for pointing that out. I updated the context to make my idea more clear:
In JavaScript, we have 2 main paradigms: functional programming, and object-oriented programming. Interfaces are specific and explicit to OOP and cannot be used in functional programming.
Mark Maksi because you updated your article, I am assuming you are not joking. Interfaces can, and are used in functional programming. Interfaces and classes are a nice way to group behaviours, and that is not exclusive to OOP
Daniel Rodríguez Rivero I updated the post because I don’t want my readers to think that interfaces are exclusive to TypeScript.
How can Interfaxes be used in functional programming other than defining types for objects? Can you show me an example in a code snippet?
Mark Maksi interfaces allow some type definitions that are not possible in plain types. Not sure what is in your mind, but ojects and classes are not exclusive to OOP. In FP classes can be used to model/group behaviour, without attaching any data to it. Option, Either are defined using interfaces that any class can implement. Here you have an example: github.com/gcanti/fp-ts/blob/master/src/Opt..