TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Allow visibility on constructors

Open bpasero opened this issue 11 years ago • 42 comments

I think it is a pretty common pattern to have a static factory method to create a class and the constructor of this class being otherwise private so that you cannot instantiate the class unless you use the factory method.

bpasero avatar Mar 13 '15 09:03 bpasero

I am using TypeScript 2.0.2 RC and still get TS1089 when I try to make a private constructor. Am I doing it wrong or is this simply not fixed?

it is working for me. make sure your command alias is pointing to the right version, and that your editor is updated to use the latest TS version.

mhegazy avatar Sep 22 '16 17:09 mhegazy

I found the problem. It was the fault of gulp-typescript which was using the wrong version of tsc despite my specifications in package.json and what was resolved on the PATH.

For anyone else having this problem, my solution was to edit my gulpfile.js and...

  1. require TypeScript before gulp-typescript as follows:
// Tool-Chain: Scripts
var tsc = require("typescript");
var typescript = require('gulp-typescript');
  1. Provide the compiler as an override when defining my build task:
// Task(s): Build TypeScript Outputs
var tsconfig = typescript.createProject("path to tsconfig", { typescript: tsc });
gulp.task('build:scripts', function () {
    let ts = tsconfig.src()
                     .pipe(sourcemaps.init())
                     .pipe(typescript(tsconfig));

    return ts.js.pipe(sourcemaps.write(".")).pipe(gulp.dest(path.join(outputs.root, outputs.scripts)))
});

stephenmartindale avatar Sep 22 '16 17:09 stephenmartindale