VSCode Angular & typings: no intellisense - angularjs

I try to set up a new project with angular 1.5.5 and I want to make use of typescript for my code. I use Visual Studio Code as my coding tool.
I added the typings for angular to my project:
typings install angular --save --ambient
I added a typings.d.ts file and a tsconfig.json file but I don't have intellisense any of the .ts files I've added...
Don't know what am I doing wrong? Can someone help me?
I try setup small project to reproduce the problem: download link
Great thx in advance!
Alexander.

I guess you must have seen an error when executing:
typings install angular --save --ambient
First of all you must install the new TypeScript Definition Manager:
npm install typings --global
then you must use this command in your project's folder:
typings install dt~angular --global --save
as explained in the quick start.
This command should create a file typings.json which should look something like this:
{
"globalDependencies": {
"angular": "registry:dt/angular#1.5.0+20160517064839"
}
}
If you're wondering what that dt prefix is, you can run:
typings search --name angular
and you will see that dt represents the source:
I think you must restart VS Code to see the effects and have intellisense.

I ran into some issues myself and here are the steps I took to make it work.
Open the terminal and run...
npm install typings -g
cd ~/root of your project
I had an error running typings install dt~angular --save --global
I install locally typings install dt~angular --save
Notice the typings folder in the root of your project. If you can't see the typings folder restart VS Code or cmd+shift+p and type reload and choose Reload Window.
In the root also is a typings.json file with the following object.
{
"dependencies": {
"angular": "registry:dt/angular#1.6.0+20170223151516"
}
}
In the root of your project create an empty jsconfig.json
After creating the jsconfig.json file I Reload Window again. I opened the app.js file and got intellisense for angularjs.

One way to get intellisense is to add a ///<reference path="../typings.d.ts" /> to the top of your typescript files. As you add definitions, make sure to add them to the typings.d.ts file.

Your file structure is wrong:
tsconfig.json should be on the root directory of you app, i.e. AngularApp.
usually, typings.d.ts is there as well.
After you move these two files, remember to change the path inside them. Ts files must be included.
//tsconfig.json
{
//...
"files":[
"typings.d.ts",
"public/app/app.ts"
]
}
//typings.d.ts
/// <reference path="typings/browser.d.ts" />
If you want to download.

Related

npm installation error CLI

I tried to install npm and run angular project but there is a warning
I ran this command npm install -g #angular/cli after installing git and node
you are missing package.json from your project. Since you have installed angular/cli globally, you should just create new project as ng new nameofproject
See here for more info https://github.com/angular/angular-cli
You need to have package.json file using which npm downloads dependencies for the project. Create a new project with the following command ng new projectName.
You are here:
C:\xampp\htdocs\angular>npm install
instead use:
C:\xampp\htdocs\angular>ng new myangular-app
When you do this it will create and download all the required files and dependencies. After this you are good to go then.
Hope this helps!
PS: Please have patience, as this can take some time to set up your new project. (It will download all the required files and dependencies to node_modules folder).

VSCode AngularJS Intellisense not working

Installed typings globally
npm install -g typings.
Installed AngularJS types
typings install dt~angular --save
jsconfig.jsong file is in the root of my angular project along with typings.json and typings folder containing the angular module typings. I restarted vscode, still nothing.
What else can I check?
For JS projects, typings should be acquired automatically. Take a look at our documentation on automatic type acquisition for more info.
If automatic type acquisition is not working for some reason, try using #types instead of using typings:
npm i --save-dev #types/angular
These typings files should be automatically picked up for intellisense in VSCode.
Then if you still don't see proper intellisense, please open an issue. Include your jsconfig.json and some example code.

How to write Protractor test scripts using Typescript along with Jasmine framework in Visual studio Code?

My project is going from standalone to Web, Our new WebSite is getting created in AngularJS so Protractor is the tool selected for Test Automation.
I want to Integrate Typescript with dependencies of Jasmine and Node so that I don't get errors such as
cannot find name Describe
cannot find name it
cannot find name Expect
Can Anyone tell me how to add Jasmine and Protractor dependencies, so that when I hit ctrl + space i'll get all options available.
I have installed Typescript. And I am getting protractor dependencies such as browser, element, by etc.
What should i do for describe,it,expect (Jasmine stuffs) ?
I use Visual Studio Code everyday to write my scripts, it's my current favourite editor for Protractor because of its built in support for TypeScript!
Here are the following things which can come into my mind which could help you setup your framework-
Download the latest VS Code version - https://code.visualstudio.com/download
Install typescript globally npm install -g typescript
Install protractor globally npm install -g protractor
Create your project folder
Setup you project folder for git, node and typescript -
npm init -f // will create default package.json stating its nodejs project
git init // will create .git file, you project is now git project
tsc --init // will create tsconfig.json stating its typescript project
Install typings and dev dependencies-
npm install --save-dev protractor // this will install protractor as a dev dependency
npm install --save-dev typescript // this will install typescript as a dev dependency
npm install --save-dev #types/jasmine // jasmine typings
npm install --save-dev #types/node // node typings
At this point you have setup your basic protractor-typescript project and you can see all the typings and dependencies in package.json. Now you are good to write your typed scripts :).
Now compile your scripts by running -
tsc or tsc -w
After successfull compilation all your javascript files would be generated.
The run protractor
protractor config.js
You can also setup your vs code for debugging with protractor which I have mentioned here - Protractor -VS Code Debugging
For more details pls refer the TypeScript Tutorial, Protractor API
The Typescript error you are observing this is due to VS Code not recognizing global typescript 2.0 version.
To solve this open vscode go to preferences--> user settings --> settings.json will be opened and enter the highlighted path as shown
Save your file and restart VSCode now you are good to go :)
I agree with the answers given. Just want to share a hack with you.
You don't need to transpile your Typescript codes to JavaScript anymore.
Create a launch.js file
require('ts-node').register({
compilerOptions: {
module: 'commonjs'
},
disableWarnings: true,
fast: true
});
exports.config = require('./config/protractor.conf.ts').config;
And kick start protractor execution like:
> protractor launch
You can save yourself from the headache of transpiling every time you make a change to typescript files.
Happy testng!

typings.json not getting updated typings install --ambient

I used to work with tsd for managing my type definitions, but as it's deprecated, I'm trying to migrate to typings which is my opinion more complicated, but should be the way to go, I guess.
I want to install a type definition and for that I use the --ambient flag.
In Visual Studio I have the typings.json file which looks like that:
{
"name": "Test",
"version": false,
"ambientDependencies": {
"angular": "github:DefinitelyTyped/DefinitelyTyped/angularjs/angular.d.ts#ca92a5b250433c38230b5f4138b36453862342bf",
"jquery": "github:DefinitelyTyped/DefinitelyTyped/jquery/jquery.d.ts#ca92a5b250433c38230b5f4138b36453862342bf"
}
}
This was automatically created when migrating from tsd to typings but now once I need a new type definition, for instance angular-route I use the following command:
typings install angular-route --ambient
This works fine, but the typings.json does not get updated.
What is the point and why am I missing? Why were angular and jquery both migrated to typings.json and when installing angular-routethe file does not get refreshed?
Actually in Typings 1.0 they did some breaking changes.
"ambient" is now "global". Just in case, installing from DefinitelyTyped must be explicit.
The following will install jQuery and save it to typings.json
typings install dt~jquery --global --save
See the link in Igor's answer for more info
You forgot --save
typings install angular-route --ambient --save
command syntax above is now obsolete and only applicable to version 0.x
Link to Typings command help
Update
As pointed out by #AndresM there are breaking changes in going from version 0.x to 1.x. See the documentation Updating From 0.x to 1.0?. The command syntax in #AndresM answer is the correct way to execute a typings command using DefinitelyTyped store and Typings version 1.x.
Now with Typescript2.0(https://blogs.msdn.microsoft.com/typescript/2016/09/22/announcing-typescript-2-0/) the global is also gone. The following will install jQuery and angular typings:
npm install --save #types/angular #types/jquery
Your package.json will then have:
"dependencies": {
"#types/angular": "^1.5.16",
"#types/jquery": "^2.0.33"
}
Your node_modules directory will have #types/angular and #types/jquery directories which contain index.d.ts files.

Package dependencies in NPM and Bower

First time user of npm and bower. I am able to install packages correctly but I am not sure how the dependencies work? As an example, I did "npm install angularjs" in my application root which created a folder "node_modules/angularjs/" with some files in it. I can also see that there is a package.json file within the angularjs folder, and it looks like it has not been processed as there is numerous packages listed in it and not installed.
Long story short, should I install all these packages manually or is there a built in feature that npm/bower can also process these sets of dependencies?
UPDATE:
I greatly lack the ability to ask precise questions, I apologise to those who have answered and did not give the correct sypnosis.
What I expect to happen:
Using npm or bower, I want to clarify that if I do an install of one of their packages, will it automatically also install the new package's dependancies or would I need to do a npm/bower install for each of the packages.json or bower.json files manually?
What I did to try make it work:
Created folder D:\Websites\TestSite
Within the folder through CMD, I did a "npm init" and ran through the guide
I followed that up with a "npm install angularjs"
A new folder was created D:\Websites\TestSite\node_modules\angularjs and within this folder there was a "index.js" and package.json file
Opening index.js I get a "require("angular");" and module.exports = window.angular.
The package.json file contains a number of dependancies which has not been installed.
My Result:
As per my expectations, npm install in point 3 above did not install the dependancies of the package.json file after it installed angularjs.
I am not sure but I assume that the index.js file needs to be included in my html and that it required the requirejs library initiated? If this is the case, then requirejs (which I do not have installed on my site) should be a dependancy for angularjs to work, and should be installed prior to giving me the ability to try and initiate it?
Am I missing a step or misunderstanding the functionality of NPM/Bower? Thank you for your patience!
Npm and Bower are great tools for managing your dependencies, i'll try to make it clear in a few words.
In general npm is used for managing your back-end dependencies and Bower is responsible for your front end dependencies.
There are 2 config files:
package.json, here are listed your dependencies that are not used in browser(e.g. bower, grunt). To install all dependencies in package.json run npm install.
Bower.json, here will be listed your "in browser" dependencies(e.g angular, jQuery). Run bower install to install all dependencies listed here in bower_components
You can find a extended guide i wrote here.

Resources