0

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?

Ismoh
  • 1,074
  • 2
  • 12
  • 35
  • I'm really not familiar with gulp, but when you define a task, the others that are specified in the array must be executed first, right? Is the task _['clean-ts']_ supposed to run _**before**_ 'compile-ts' ? –  Nov 20 '17 at 13:11
  • yes clean-ts runs before compile-ts. – Ismoh Nov 20 '17 at 14:31
  • For everyone whos interested in: https://stackoverflow.com/questions/47472464/how-to-provide-global-typescript-classes-via-webpack-bundle-in-js – Ismoh Nov 30 '17 at 10:43

0 Answers0