I'm new in web dev, and I am currently reading about Angular, and other frameworks. I know that Angular is written in TypeScript, but I'm wondering if it is possible to develop an app using Angular and JavaScript?
As TypeScript is a superset of JavaScript, existing JavaScript programs are also valid TypeScript programs.
(Wikipedia)
Meaning, All JavaScript is valid TypeScript. TypeScript only adds thing to the JavaScript language, you are not required to use these new features such as Types, you can skip them and just type normal JavaScript.
However, when you develop Angular applications you become a user of the #angular-cli package and tool which helps you generate boilerplate code for your files and projects. This code that is generated by the CLI is written using TypeScript features -- So if you for some reason refuse to use TypeScript, it will make your development experience worse since you will not be able to use all of the Angular tools that help your development, such as the CLI or the Documentation.
Yes.
Angular does use .ts files by default. But if you write simple javascript code in them it will still work. Valid javascript is also valid typescript.
Once you get up and running with angular though you will see the benefits of Typescript are worth it. It won't make sense to write an Angular app using just javascript.
The question you should ask yourself is why would you do that? TypeScript became a standard for large front-end applications. It stays ahead of the curve of EcmaScript, bringing more features that are only going to become part of the standard and then implemented. Not to mention static types, which ensure all sorts of runtime errors just never happen.
Also, TypeScript is a superset of JavaScript, you can write your ol' regular JS in .ts files and never worry about all the goodness TypeScript gives you if that is what you want.
Yes, You can but it would not be sophisticated and well-timed application If you want to avoid Typescript. Even ECMAScript 2017 also very similar to Typescript. So, It would be definitely better to go ahead with Typescript.
Introduction to Angular concepts
Angular is a platform and framework for building single-page client applications using HTML and TypeScript. Angular is written in TypeScript. It implements core and optional functionality as a set of TypeScript libraries that you import into your apps
read more
Related
I wonder what the disadvantages would be if one decides to write Express.js applications or APIs with TypeScript, instead of JavaScript.
The only objective, non-opinion-based disadvantage I can come up with is that you have to compile the TypeScript before using it with Node.js, which complicates things (slightly) — using the compiler in your toolchain, using source maps to understand where errors in production occurred in the real code, etc.
TypeScript translates itself to JavaScript. So unless you absolutely need typescript, you can keep writing JS.
Thus why take the headache of transpiling during compile time and increase your development effort.
I currently have a large JavaScript application with a lot of code written in vanilla Javascript for a specific platform for where I work.
I need to transform this into a web application I can open in the browser. This should be able to be done relatively easy by swapping out the components from my current application to the components of another web technology.
However since Angular2 is written in TypeScript, if I was to choose it as the framework I use, should I really also be rewriting the rest of my non-component JavaScript to TypeScript to or will I not need to do this.
Would it be a bad idea to have an application which was half TypeScript and half JavaScript like this?
It's not a bad idea to mix TypeScript and JavaScript. I do it every day. But you have to now that it may be very painful in some cases. So I can only advice to enforce migration to TypeScript as fast as possible.
I would suggest you to read this introduction to migration from JavaScript to TypeScript: https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html
This might also be a valuable source: https://basarat.gitbooks.io/typescript/content/docs/types/migrating.html but I have the impression that the author has a very narrow opinion on how to work with typescript so just don't take everything there as it is, but just as a suggestion.
There are also a lot of other resources about migrating from JavaScript to TypeScript.
For the last month of migration to TypeScript I can say, that in many cases you can simply change your JavaScript to a TypeScript file and add exports. Than you need to add the needed imports in the other places and everything works just like before.
If you can make sure, that you only use old JavaScript in your TypeScript and not the other way round you can split your project into to packages. Load the JavaScript into global as done before and than create Typings for the parts of your JavaScript you use in TypeScript.
Is it possible to mix the three Languages in one Angular-2 Project, e.g. writing the App in Typescript a Componet in Dart an another in JS?
JS is TypeScript. TypeScript is a superset of JavaScript but if you use the Angular2 JS library to build components, it's unlikely that these components will work with components built with TS (not entirely sure here).
You definitely can't mix Dart with any of the other two.
An Dart Angular2 application depends on being built as a whole and this won't work with mixed in JS or TS components.
What can be done is to bootstrap 3 root components where each one is built with a different language, but within one root component mixing languages is unlikely or impossible to work (see above).
Yes, it is possible since they are all will be translated to JS, but I would not recommend doing that.
The reason to avoid such a mix is that it will be difficult to maintain the code. Each of these languages has its own patterns and ways of doing things. By mixing them you will need to create redundant abstractions and mappings (e.g. TypeScript typings for Dart's components), unit-tests will be segregated by technology. Just imagine that one day you will need to add one more developer to the project. If there is only one of these technologies the search and evaluation of a candidate will be as simple as specifying a single skill in a job description. But when you have 3 of them it becomes difficult to find a developer having all these skills. Even if you will find this "ninja" there is still a need to teach him how you are using the mix. You will need to explain to him all hacks/tricks of build scripts and then transfer a sacral knowledge when and why to prefer one technology over another.
I would recommend you to stick to TypeScript because it is a superset of JS and its features are compliant with ECMA standard.
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.
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
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.
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.
I am very new into web design and applications. I know Angular JavaScript is a "JS framework" that extends HTML attributes. TypeScript is a "superset" of JS which allows static representation of JS dynamic type system. I wonder what is the relationship between these two? Can they be used together?
Angular JavaScript and TypeScript?
TypeScript is just a language that transpiles to JavaScript.
You can use either with AngularJS.
More
more about typescript : https://basarat.gitbooks.io/typescript/content/docs/why-typescript.html
Angular JavaScript is the frame work for front-end web application based on JavaScript maintained by Google, While on the same place Typescript is statically typed programming language designed by Microsoft corporation. Typescript is being used with AngularJS as it can evolve quicker since they're not bound by the ES standard. Successful features that are introduced via Typescript may make it in to core JavaScript over time, so it's a way to influence the standard as well.