I read the following question, because my TypeScript class is undefined
in antoher javascript file. In the other question M98 said to add a standalone to browserify to use it globaly.
I am new to browserify and typescript also gulp.
TypeScript class:
export class Test {
static log = function(what: string) : void {
console.log(what);
}
}
//export { Test }
Browserify / Gulp Task:
gulp.task('compile-ts', ['clean-ts'], function () {
var tsFiles = glob.sync(config.js.tsSource);
return browserify({
standalone: "tsLib",
basedir: ".",
debug: true,
entries: tsFiles
})
.external(["jquery"])
.plugin(tsify)
.bundle()
.pipe(source("modules.js"))
.pipe(gulp.dest(config.js.tsDest));
});
My typescript class is undefined in my test javascript file, because of that I created another typescript file and add the following:
import {Test} from "./test-file";
export function log(log:string) {
Test.log(log);
}
I want to use my TypeScript class in a JavaScript file as the following example:
function onLoad() {
tsLib.log("test"); // I dont want that
Test.log("test"); // I would like to use this, but it's undefined
}
tsLib.log
is a workaround to use my Test class, but I just want to call log as Test.log("whatever");
.
Is this possible?
Can anyone give me hint?
Edit: If I use the TypeScript file without browserify and just use the TypeScript compiler it seems to be working, but I want to understand this issue. What am I doing wrong?