By utilizing an interface, you can incorporate polymorphism into your code. Javascript does not require the use of interfaces to achieve this flexibility due to its dynamically typed nature. For instance, consider an array containing classes with similar methods:
Circle()
Square()
Triangle()
To gain a better understanding of how polymorphism functions, refer to David Kruglinsky's MFC Book (specifically written for C++).
In these classes, by implementing the draw()
method and pushing instances into the array to then call the draw()
methods in a loop, you essentially create an implicit implementation of an abstract class. While not explicitly defined, Javascript allows for this approach without issues regarding interface method implementation requirements.
An interface serves as a contract that mandates the implementation of all specified methods, which is necessary when utilizing static typing.
The transition from dynamic to static typing in languages like Javascript may spark debate, as the latter is inherently designed to be dynamic. Experienced developers are accustomed to and comfortable working within Javascript's dynamic framework.
It remains unclear to me why one would opt for Typescript over Javascript, especially considering the efficient and cost-effective enterprise website development opportunities offered by NodeJS in tandem with Javascript and MongoDB.
Typescript was developed by Anders Hejlsberg, known for also creating C#. Conversely, another developer at Microsoft explored a different path by infusing C# with dynamic capabilities akin to Javascript - where dynamics manifest at runtime rather than compile time.
I possess 40 years of development experience spanning both C-like languages and Javascript and observe Visual Studio facing challenges such as slow compiling and lackluster hot reload features, while Nodejs shines and excels in performance.
Moving forward, reliance on interim solutions like sass, less, angular, react, and typescript may become obsolete as native Javascript emerges as the preferred choice. Javascript has reached maturity, and successful integration requires adept software architects driving innovation.