2

I am using grunt:

  "dev-build": {
                src: ["src/**/*.ts", "typings/vendors.d.ts","typings/tsd.d.ts", "!libs/**/*.ts"],
                    outDir: "artifacts/dev",
                    watch: "src/**/*",
                    options: {
                        // comments: true,
                  //      baseDir: 'src/',
                        module: "amd",
                        target: "es5",
                        sourceMap: true,
                        declaration: true, //inlineSourceMap :true,
                        //emitDecoratorMetadata:true,
                        //experimentalDecorators:true,

                    }               

            }

and everything compiles fine:

"TypeScript compilation complete: 8.97s for 256 TypeScript files."

but then after changing a file (adding a linebreak) without changing the code the compile breaks with the watch:

### changed  >>src/FxsPortal/FxsBaseItemViewModel.ts
Compiling...
### Fast Compile >>src/FxsPortal/FxsBaseItemViewModel.ts
Using tsc v1.6.2
C:/dev/AscendXYZ Portal/src/FxsPortal/FxsBaseItemViewModel.ts(2,21): error TS2307: Cannot find module 'knockout'.

I know there are no errors since I can compile it all manually. I dont seem to understand why it do not work when the watch of ts-grunt triggers.

Poul K. Sørensen
  • 16,950
  • 21
  • 126
  • 283

2 Answers2

1

For reference I just wanted to share how I solved this using an external watch.

 watch: {
            devBuildWatch: {
                files: ['src/**/*'],
                tasks: ['ts:devBuild'],
                options: {
                    spawn: false,
                },
            }
        },

and a onchange action

 var changedFiles = {};

    var onChange = grunt.util._.debounce(function () {
        grunt.config('ts.devBuild.src', Object.keys(changedFiles).concat([ "typings/vendors.d.ts","typings/tsd.d.ts", "!libs/**/*.ts"]));
        changedFiles = Object.create(null);
    }, 50);

    grunt.event.on('watch', function (action, filepath) {
        changedFiles[filepath] = action;
        onChange();
    });
Poul K. Sørensen
  • 16,950
  • 21
  • 126
  • 283
0

I dont seem to understand why it do not work when the watch of ts-grunt triggers.

Those errors can be safely ignored. The reason why they show up is because grunt is just driving tsc from the command line and only passing it individual files.

More

If you really care you can use reference tags to bring in the global .d.ts files (files that are not coming in via import/require). But I highly recommend against it. You should have an IDE open that will give you the real errors anways (...cough atom-ts ...)

basarat
  • 261,912
  • 58
  • 460
  • 511
  • Thanks! I will look into atom-ts. currently I am using the VS typescript project side by side to give highlight. I understood the documentation such that reference was a outputfile? Is this wrong, so I can put my tsd.d.ts into reference? (can it take an array also)? – Poul K. Sørensen Oct 13 '15 at 07:18
  • sorry, you ment reference in the ts files. not the option in ts-grunt – Poul K. Sørensen Oct 13 '15 at 07:21
  • take a look at my answer for external watch. If we had an option on ts-grunt such the internal watch did similar of concatting a list of type definitions. – Poul K. Sørensen Oct 13 '15 at 07:26
  • Hi @basarat, I also encountered this issue. Is there a new solution for that? Ignoring the console is not a great one, kinda misses the purpose of watch IMO. – mrgoos Jun 12 '16 at 16:33
  • @basarat - the real issue here is that, true, I can ignore the errors and the file will compiled but since it's an error, when I'm undoing the latest code change I get: `No file changes were detected. Skipping Compile`- so I'm staying with the compiled code that produced the error. – mrgoos Jun 12 '16 at 20:21