I am working with a third-party angular2 plugin named .

The FileUploader typescript class is defined as:

export class FileUploader {
  public url:string;
  ...
  public queueLimit:number;
  public _nextIndex = 0;
  ...

This generations a javsacript file with:

 FileUploader = (function () {
                function FileUploader(options) {
                    ...                    
                    this._nextIndex = 0;
                    ...
                    this.url = options.url;
                    ...

Notice that the queueLimit variable does not get generated in the javascript file.

If I give queueLimit as default value then it is generated.

export class FileUploader { public url:string; ... public queueLimit:number; public _nextIndex = 0; ...

 FileUploader = (function () {
                function FileUploader(options) {
                    ... 
                    this.queueLimit = 50;                   
                    this._nextIndex = 0;
                    ...
                    this.url = options.url;
                    ...

This causes problems when using that variable in js file.

share|improve this question
  • 2
    It would only cause an issue if later you use it expecting it to be initialized when you never initialized it. That has nothing to do with Typescript, that's just poor coding practice. – David L Apr 5 '16 at 20:28
  • It's not initialized, that's why it's not generated in javascript file. That's it. – Ajay Apr 6 '16 at 6:17

Notice that the queueLimit variable does not get generated in the javascript file.

This is by design. Not having the variable initialized as similar effect to having it initialized

That is to say the following have similar behaviour:

class Foo {
    bar;
}
class Foo {
    bar = undefined;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.