0

I'm using angular beta .8 and I'm using gulp to try and deploy my app to apache http server.

I have a .ts file like this:

import {Component, OnInit} from 'angular2/core';

export class Calendar implements OnInit {

date: any;

   ngOnInit() {
       $('.datepicker').pickadate({

Which when I try to launch "gulp" command, it shows multiple errors, currently I am trying to solve this ones:

error TS2304: Cannot find name '$'.

I don't know how to provide this for the transpiler and when looking arround I've found two branches of solutions: adding /// <reference path="../node_modules/angular2/typings/browser.d.ts" /> to where I have the bootstrap, which I did, and adding typings which I currently have like this:

{

  "ambientDependencies": {
    "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c",
    "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#bc92442c075929849ec41d28ab618892ba493504"
  },
  "globalDependencies": {
    "es6-collections": "registry:dt/es6-collections#0.5.1+20160316155526",
    "es6-promise": "registry:dt/es6-promise#0.0.0+20160614011821"
  }
}

And it's solved nothing, so I was wondering what else do I need to make this errors go away.

I also have other errors which I am not sure if they are related, mainly it complains about not finding name 'Observable', 'OnInit', a couple .js functions that I make reference in my .ts files, and a few

TS2307 cannot find module 'ng2-material/all' 

or different typescript files that it seems it's not finding.

I'd like to mention that code does work if executed on plunker or in the browser, it isn't working when trying to deploy it with gulp.

I've read this thread and applied everything but as I said it isn't working for me Angular 2 typescript can't find names

Community
  • 1
  • 1
monkey intern
  • 705
  • 3
  • 14
  • 34

1 Answers1

0

For the first error, it looks like you're trying to use jQuery ($) but the typescript compiler doesn't know what that is. Try adding the declare statement as below:

import {Component, OnInit} from 'angular2/core';

declare var $: any;

export class Calendar implements OnInit {
   ...

This just tells the compiler that $ is a variable of type 'any' defined in some 3rd party javascript file (jquery in this case).

user2444499
  • 757
  • 8
  • 14
  • If I do what you say I get "ts1206 decorators are not valid here" and if I put it after the export statement I get "error ts1068 unexpected token" and "error ts1005 ';' expected" when there shouldn't be any ; so I believe syntax is not exactly right? – monkey intern Aug 16 '16 at 09:41
  • 1
    @monkey: see modified code above. If that's not fixing the first error, then it's likely some other issue. – user2444499 Aug 16 '16 at 10:26