grunt-ts icon indicating copy to clipboard operation
grunt-ts copied to clipboard

complie the file "node.d.ts" with "the error TS2304"

Open flyzb618 opened this issue 10 years ago • 9 comments
trafficstars

my tsc is 1.5 beta ,and my gruntfile.js is below:

module.exports = function (grunt) {
  grunt.initConfig({
    ts: {
      default: {
        src: ["src/**/*.ts", "!node_modules/**/*.ts", "!typings/**/*.ts"],
        out:"bin/out.js",
        options: {
          fast: 'never',
          module: 'commonjs',
          declaration: true,
          force: true
        }
      }
    }
  });
  grunt.loadNpmTasks("grunt-ts");
  grunt.registerTask("default",["ts"]);
};

when I use grunt-ts,I always met "TS2304 error".But I use tsc in VSCode , it works fine. who can tell me, why ? (btw: I had reinsalled the node.d.ts file)

flyzb618 avatar Jul 19 '15 14:07 flyzb618

Not sure its related but .... Don't combine --out with --module. In fact with --module commonjs there is no need for out :rose:

basarat avatar Jul 20 '15 04:07 basarat

When you run tsc, is it referencing the tsconfig.json file? If so, what are the contents of that file?

Why are you excluding the typings folder in the src array? Normally you need to include the typings files if you want a successful compile.

nycdotnet avatar Jul 21 '15 21:07 nycdotnet

I seem to experiencing the same problem, but it happens with jquery, angular and angular-route. Here is my GruntFile

grunt.initConfig({
        ts: {
            options: {
                compile: true,                 // perform compilation. [true (default) | false]
                comments: false,               // same as !removeComments. [true | false (default)]
                sourceMap: true,               // generate a source map for every output js file. [true (default) | false]
                noImplicitAny: true,          // set to true to pass --noImplicitAny to the compiler. [true | false (default)]
                fast: "watch",                  // see https://github.com/TypeStrong/grunt-ts/blob/master/docs/fast.md ["watch" (default) | "always" | "never"]
                target: 'es5',
                compiler: 'f:\Development\Typescript\TypeScript-master\bin\tsc'
            },
            dev: {                          // a particular target
                src: ["app/**/*.ts", "vendor/typings/**/*.ts"], // The source typescript files, http://gruntjs.com/configuring-tasks#files
                html: ["app/**/*.html"], // The source html files, https://github.com/basarat/grunt-ts#html-2-typescript-support
                reference: "./app/ref.ts",  // If specified, generate this file that you can use for your reference management
                out: 'app/out.js',         // If specified, generate an out.js file which is the merged js file
                watch: 'app'
            }
        }
    });

I am using the tsd program to pull down the typings from DefinatelyTyped. I am using IntelliJ but using Grunt-TS for the typescript compiler so I can add the watch for all directories and output to single file (learned from @basarat videos).

However my console is spewing out loads of complaints. Any one any idea what's going on ?

AnthoniG avatar Aug 09 '15 03:08 AnthoniG

@AnthoniG : compiler: 'f:\Development\Typescript\TypeScript-master\bin\tsc' escape \ or use / instead. Does that help? :rose:

basarat avatar Aug 10 '15 01:08 basarat

@basarat Brilliant thanks. I also upgraded to the latest grunt-ts as well as doing above and it all works now.

On a seperate note: I am having to use the html to ts because of Angular's funny secureurl won't load templates off my own domain. So I am passing in the template via the string now instead of the url. As you can imagine, this is making my out.js file rather large.

1] Is there a way to seperate the html data into it's own javascript file? (if so, how would I do this please?)

2] Also, I am not 100% par fe with grunt, but I would like to run a minimizer. Using my Gruntfile from above, could perhaps show me how to tack on a minimizer please ?

(PS: I use the public static $inject in all of my controllers, services, etc to help against minification).

AnthoniG avatar Aug 10 '15 13:08 AnthoniG

Look into grunt-contrib-uglify. I will add a blurb about how to integrate it to the docs later, but pretty much you npm install it, then add an uglify section in your initConfig and add it to your target. The trouble is that you can't minify with "watch" because grunt-ts doesn't yield I that mode (yet) so you'd probably want to have two separate targets. A dev one that watches and a release one that builds and then minifies and quits.

nycdotnet avatar Aug 10 '15 15:08 nycdotnet

Hi @nycdotnet ,

I think I am going to wait until you do the docs about it, because you totally lost me there :) Like I said very new to grunt. All my compiling has been inside an IDE, so kinda spoilt lol

AnthoniG avatar Aug 10 '15 20:08 AnthoniG

I am sorry. Reading back on that it was completely jargon filled and not useful for someone just starting out. Hope will be soon. If you have a Pluralsight subscription, you might benefit from my course Practical TypeScript Migration where I demo grunt-ts and also show minification.

nycdotnet avatar Aug 10 '15 20:08 nycdotnet

Don't have a Pluralsight subscription at moment, but hoping to get one soon as I've seen some good tutorials on there (especially about Angular / Typescript etc).

Look forward to the docs :)

AnthoniG avatar Aug 10 '15 21:08 AnthoniG