1

So, I'm a big fan of using interfaces in Java. I am trying to relate that to AngularJS. I read up on the concept of duck typing for Javascript, which is fairly straightforward. Is there anything the base AngularJS library provides in addition to that that would be similar to the concept of an interface? I know javascript is loosely typed, but without using typescript, is there anything similar?

I'm only familiar with AngularJS to the point that I can jump into existing code and change functionality, I am not able to develop a well designed Angular application from scratch. We are using Angular version 1.X.

Samuel French
  • 665
  • 3
  • 11
  • 22
  • The presupposition about TS doesn't give the question a chance. TypeScript is a superset of JavaScript that offers static typing. Obviously, it wouldn't be created if JS offered typing. So yes, it has interfaces and stuff, and actually makes the adoption of JS libraries that have typings easier. Angular is [among them](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/angularjs). TS-friendly IDE can help an Angular dev in writing more code and RTFMing less. – Estus Flask Aug 12 '16 at 20:38

3 Answers3

2

There's nothing angulary that would be similar to an Interface. You don't typically define an Interface in JavaScript, so most likely what you want to do is an anti-pattern in JavaScript.

Here's another SO question that digs into why duck typing isn't typically something you do with JavaScript.

Duck Typing in Javascript

Community
  • 1
  • 1
Todd Miller
  • 301
  • 1
  • 6
1

I'm sorry but TypeScript is what you should use. That's my opinion. AngularJS is more like a framework that helps you with Model View Controller. It is not a library and it doesn't extend JS in that way.

0

the best thing is using Typescript for interfaces. Because JavaScript doesn't have interfaces. Here Typescript will transpiles your code to resulting JavaScript. I think Interfaces are only for strong typing and better tooling support to build a code without any errors.