microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.77k stars 12.46k forks source link

Modules imports #2907

Closed JanHuege closed 9 years ago

JanHuege commented 9 years ago

I am currently trying out typescript 1.5 alpha but the compiler always tells me:

src\Person.ts(4,1): 1128 Declaration or statement expected. src\Person.ts(4,8): 1109 Expression expected. src\Person.ts(4,13): 1005 ';' expected. src\Person.ts(4,22): 1005 ';' expected. src\Person.ts(4,27): 1005 ';' expected.

when trying to import modules like that:

import { } from "angular2/angular2";

EDIT: fixed it but now: src/Person.ts(4,25): error TS2307: Cannot find external module 'angular2/angular2'.

RyanCavanaugh commented 9 years ago

Do you have a .d.ts file defining angular2 ?

JanHuege commented 9 years ago

No there is no .d.ts file in there I got 2 Versions 1 angular2 only including d.ts and one with .js files and maps

RyanCavanaugh commented 9 years ago

You will need some definition for angular2/angular2 in order to not get that error.

JanHuege commented 9 years ago

How do I get those, they arent included in the modules folders I get from npm and github

MarcBanc commented 9 years ago

http://definitelytyped.org/

2015-04-24 19:57 GMT+02:00 KhaosTheory1012 notifications@github.com:

How do I get those, they arent included in the modules folders I get from npm and github

— Reply to this email directly or view it on GitHub https://github.com/Microsoft/TypeScript/issues/2907#issuecomment-96013155 .

mhegazy commented 9 years ago

courtesy of @alexeagle, here is the Angular2 typings https://github.com/rkirov/ng2-ts-hello/blob/master/typings/angular2/angular2.d.ts

alexeagle commented 9 years ago

Note, that is a minimal .d.ts for our demos, we are working right now to publish one for the whole angular2 library.

JanHuege commented 9 years ago

I am sorry to bother you but I don't get it. I am trying to setup a project for a little tryout at university for a lecture and we are supposed to use recent angular2 and typescript alpha releases. Problem is, none of us have worked with it before so we are kind of new to the whole js world. Is there any way of getting a version of angular2 with those definitions or a stepbystep guide. My team and I are searching since a week now to set something up, we can start working with. We looked at the ngconf demo but for our own project we can't use any of those angular2 versions. At least we always get some kind of error. I know it is all in development right now and I would work with angular 1.x but like I mentioned before we are supposed to work with angular2 and typescript.

mhegazy commented 9 years ago

can you try the steps in here: https://github.com/rkirov/ng2-ts-hello

mhegazy commented 9 years ago

I will update ngconf2015demo to follow the same as well

mhegazy commented 9 years ago

@KhaosTheory1012, https://github.com/Microsoft/ngconf2015demo is now updated as well.

Thanks @alexeagle and @rkirov for the help!

JanHuege commented 9 years ago

Thank you very much, I appreciate your help!

mhegazy commented 9 years ago

Glad this helped. Please let us know if run into other issues.

JanHuege commented 9 years ago

We came to another problem. We want to import a module to fetch some data from our RESTapi but the angular2.d.ts file doesn't describe how to get there. So I wonder how can we edit it so we can import stuff like zone and xhr.

mhegazy commented 9 years ago

@KhaosTheory1012 i will need more information about the issue you are running into. Is this similar to #2920, you will need to define the shape of the module you are importing. I would look for typings of popular libraries on http://definitelytyped.org/; if it is your own library you will need to hand author your .d.ts for it. here are some documentation to get you started: https://github.com/Microsoft/TypeScript/wiki/Writing%20Definition%20Files

JanHuege commented 9 years ago

Okay so we are trying to import modules other than the ones defined in angular2.d.ts (https://github.com/Microsoft/ngconf2015demo/tree/master/angular2) We are using this version of angular2 because every other one we wanted to use with typscript didn't work or at least we didn't know where to get already written .d.ts files from. But everything we are trying to import is from angular2. No library of our own. At the moment we are meant to build an app that is fetiching data from a RESTapi. So we wanted to access the modules from angular2: zone and xhr to get the functionality of $http $resource

mhegazy commented 9 years ago

@alexeagle, any recommendations here?

alexeagle commented 9 years ago

The angular2.d.ts is very minimal, so it's expected that you fall off a cliff right now as soon as you try to do something beyond the demo. For now, you can just use type any to short-circuit the type-checking in the TypeScript compiler as a workaround.

We need to figure out what will be in the .d.ts we publish, and what won't. For example, zone is a third party library Angular depends on, so the typings for it ought to be published independently (but I don't see them on DefinitelyTyped). We also need to figure out the mechanics of generating and bundling the angular2.d.ts from our sources. I plan to investigate https://github.com/TypeStrong/dts-bundle today, and Mohamed I might have some questions for you along the way...

JanHuege commented 9 years ago

Is there a way to use the actual angular2 repository with typescript 1.5 beta now? Or will it only work when the transition from atscript/es6 to .ts is done?` Because we are currently running into the problem of not being able to use things like EventEmitter or other things like forms.

alexeagle commented 9 years ago

The build system for the angular2 repo is pretty complex. The whole thing is already parsed by typescript compiler, but for some parts we use the emit from tsc and for other parts still traceur. More complex yet, that mix depends if you are in node or targeting a browser. And it will change a lot next week. I'm not sure the status of forms but I think that is still pre-alpha. Everything that's ready to use should be shipped in the two bundles we distributed (eg. the one included in the quickstart repo). Please file a separate issue on the angular/angular repo if you find features which should be part of developer preview release, but which you cannot use through the bundle we distribute. Thanks for sticking with us during the early pre-beta days :)