Skip to content

ES6 Modules and *.d.ts files with compiler #3658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
grofit opened this issue Jun 27, 2015 · 6 comments
Closed

ES6 Modules and *.d.ts files with compiler #3658

grofit opened this issue Jun 27, 2015 · 6 comments

Comments

@grofit
Copy link

grofit commented Jun 27, 2015

I am currently working with aurelia which uses ES6 module loading (System) and it is great as I do not need to worry about slapping reference tags everywhere. Now my IDEs (VS/Webstorm) know about the d.ts files so while I am developing they know what types come from where. i.e:

import {Aurelia} from "aurelia-framework"

export function configure(aurelia: Aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging()
    .plugin('aurelia-animator-css');

  aurelia.start().then(a => a.setRoot());
}

It knows in the IDE that aurelia-framework is included within aurelia.d.ts which is in another folder in the solution. So this all resolves great and makes for a much better development experience, however the problem comes when I want to compile my TSC files outside of the IDE.

So for example I want to move all my /src/*.ts files to /dist/*.js files, now I am currently using gulp and gulp-typescript passing in the 1.5 beta tsc object for compilation, and it all compiles but the compiler throws up errors like:

src\animation-main.ts(1,23): error TS2307: Cannot find external module 'aurelia-framework'.

So I am unsure how to resolve this for the compiler, as the IDE knows its there, and there are no options for me to just tell the TSC where all the *.d.ts files live, so is there a way to deal with this? as the IDEs can do it, as they have outside knowledge of the descriptor files so is there some way to just tell to the compiler where all the d.ts files are?

Again just want to mention it currently outputs all the *.ts files as *.js files fine and it all works, its just it will spit out a lot of errors giving the impression its not working.

@delebash
Copy link

I think you could try using a tsconfig.json file altough I have not tried this yet but I think it should work. see https://github.com/Microsoft/TypeScript/wiki/tsconfig.json also #2865

@grofit
Copy link
Author

grofit commented Jun 27, 2015

I did look at using the typescript config file before I even had this problem, but for larger projects it is just un-maintainable to have to put in each file, I know they are working on exclusions but its still not ideal. That aside the tsconfig still interacts with the TSC so if the project notion in tsconfig would fix this, ideally there should be a way to do this manually with TSC without the config file.

@delebash
Copy link

@grofit I am using Phpstorm 9 EAP and gulp-typescript and I do not have any problems with the compiler, no errors, beside 1 where a d.ts file needs updating. I am using the typings folder in the root of my project from https://github.com/cmichaelgraham/aurelia-typescript/tree/master/master/typings.

Here is my build.js file if that helps.
https://gist.github.com/delebash/d346d139bbb8659e52a1

Also with the latest Phpstorm and Webstorm you can just use new TS ES6 Import statement syntax, ie import 'aurelia-framework' instead of using the old TS require('aureila-framework').

@grofit
Copy link
Author

grofit commented Jun 28, 2015

Ah I think the reason why yours works is because you have set noExternalResolve and are passing in the *.d.ts files, I tried doing this but it threw up errors with the aurelia.d.ts files, but I had not set the noExternalResolve, let me try that as I think this may be the solution.

Also on a side note how come you are compiling for commonjs and not system?

@delebash
Copy link

Good hope that works for you. As far as commonjs, typescript had a problem awhile ago which is now fixed and I guess I just haven't updated it to systemjs, no particular reason :)

@grofit
Copy link
Author

grofit commented Jun 28, 2015

for anyone else here my issues were down to me using an older version of the aurelia.d.ts file, there is only a temporary 1.5 one which is only available on a specific branch of the above project:

https://github.com/cmichaelgraham/aurelia-typescript

Also one other thing to note, it complains that it requires a module argument, which I am passing as system which is apparently supported in TS 1.5. If I move it to commonjs it works fine, so I assume it means 1.5 final not 1.5 beta.

Anyway problem solved, will close now.

@grofit grofit closed this as completed Jun 28, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants