I'm building a node app, and inside each file in .js used to doing this to require in various packages.
let co = require("co");
But getting
etc. So using typescript it seems there can only be one such declaration/require across the whole project?
I'm confused about this as I thought let
was scoped to the current file.
I just had a project that was working but after a refactor am now getting these errors all over the place.
Can someone explain?
I got this error when upgrading
gulp-typescript 3.0.2 → 3.1.0
Putting it back to 3.0.2 fixed it
Use
IIFE(Immediately Invoked Function Expression)
, IIFEI got the same problem, and my solution looks like this:
Now we can use it on the server side:
And on the client side too:
And, of course, a gulp-file for all of this:
Updated. Of course, it's not neccessary to compile typescript files separatly.
runSequence(['ts1', 'ts2', 'ts3'], 'browserify', callback)
works perfect.The best explanation I could get is from Tamas Piro's post.
TLDR; TypeScript uses the DOM typings for the global execution environment. In your case there is a 'co' property on the global window object.
To solve this:
Edit tsconfig.json in the TypeScript project directory.
let
is used to declare local variables that exist in block scopes instead of function scopes.The latest preferred way of importing an external module is the ES6 syntax anyways, which contains no explicit assignment: