3

I'm a programmer in ASP.NET-MVC, and I want to add AngularJS in my projects. I really like this framework, but the problem is Visual Studio can't detect errors at the debugger level, so when I make some syntax errors I spend more time to find errors.

Is there a feature to add for helping to work with AngularJS?

3
  • This sounds like a feature request to the Visual Studio team, rather than a specific programming question Commented Oct 26, 2015 at 16:34
  • I would suggest you to look at TypeScript Commented Oct 26, 2015 at 17:32
  • @youssefelamraoui, I made a significant edit to my answer. I see you've already accepted it, but read if you're interested. Commented Oct 26, 2015 at 19:01

1 Answer 1

1

To answer your question directly, let's look at the de facto definition of strongly typed as it is discussed here:

In a "strongly typed" language, it is not possible for the programmer to work around the restrictions imposed by the type system. This term is almost always used to describe statically typed languages.

JavaScript is untyped. There are no restrictions imposed by the type system to even work around (until runtime). Hence, you cannot achieve "AngularJS strong typing" with vanilla JavaScript.

That said, you can use JavaScript and catch type-related errors. Augmented JS (TypeScript or Flow annotations) can achieve full static typing, and a subset of full static typing can be achieved with type inference on Vanilla JS (Flow without annotations). Read on for details.


  • Use the statically typed TypeScript. It compiles to JS and is usable within powerful IDEs like Visual Studio.

    class Person {
      private name: string;
      private age: number;
      private salary: number;
    
      constructor(name: string, age: number, salary: number) {
        this.name = name;
        this.age = age;
        this.salary = salary;
      }
    
      toString(): string {
        return `${this.name} (${this.age}) (${this.salary})`; // As of version 1.4
      }
    }
    

  • Use an analysis tool like Flow. Flow will analyze vanilla JS for obvious type errors (misuses of inferred types):

    /* @flow */
    
    function foo(x) {
      return x * 10;
    }
    
    foo('Hello, world!');
    

    throws

    7: foo("Hello, world!");
       ^^^^^^^^^^^^^^^^^^^^ function call
    4:   return x*10;
                ^ string. This type is incompatible with
    4:   return x*10;
                ^^^^ number
    

    and you can use annotations to augment vanilla JS for more powerful type checking:

    /* @flow */
    
    function foo(x: string, y: number): string {
      return x.length * y;
    }
    
    foo('Hello', 42);
    

    throws

    4:   return x.length * y;
                ^^^^^^^^^^^^ number. This type is incompatible with
    3: function foo(x: string, y: number): string {
                                           ^^^^^^ string
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.