I'm declaring two private, static and read—only properties in a class body. At the class methods, I'm not trying to get the properties by using indexing expressions in the class object, I'm using destructuring assignment in a const
declaration.
There's no problem with the destructuring assignment, but if I don't try to index my class to get these private properties, TypeScript gives me the following warnings:
'PROGRESS_BAR_WIDTH' is declared but never used.
'PROGRESS_BAR_HEIGHT' is declared but never used.
I've created an issue at the TypeScript GitHub repository, but got no help yet.
A note: when these properties aren't private (public), these warning fade in. I use these private-static (and read—only) properties in the init
method, which isn't static.
Here's my code:
import {PICTURES} from './../data/pictures';
import {WAVES} from './../data/waves';
import {GlobalBounds} from './../constants/global-bounds';
const stuffs = [];
export class PreloaderContainer extends createjs.Container
{
private static readonly PROGRESS_BAR_WIDTH:number = 183;
private static readonly PROGRESS_BAR_HEIGHT:number = 6;
private progressBar: createjs.Shape;
private progressWrapper: createjs.Shape;
public constructor ()
{
super();
this.init();
}
private init () : void
{
const {PROGRESS_BAR_WIDTH, PROGRESS_BAR_HEIGHT} = PreloaderContainer;
const progressWrapper = new createjs.Shape;
const progressBar = new createjs.Shape;
progressWrapper.graphics
.setStrokeStyle(1)
.beginStroke('#646464')
.drawRect(0, 0, PROGRESS_BAR_WIDTH,
PROGRESS_BAR_HEIGHT);
progressWrapper.x =
progressBar.x = (GlobalBounds.WIDTH / 2) - (PROGRESS_BAR_WIDTH / 2);
progressWrapper.y =
progressBar.y = 300;
progressBar.graphics
.beginFill('#646464')
.drawRect(0, 0, 20,
PROGRESS_BAR_HEIGHT);
this.progressBar = progressBar;
this.progressWrapper = progressWrapper;
this.addChild(progressBar);
this.addChild(progressWrapper);
this.preload();
}
private preload () : void
{
let loadedFiles:number = 0;
//const len:number = stuffs.length;
const queue = new createjs.LoadQueue;
queue.addEventListener('complete', function () : void
{}, false);
queue.addEventListener('fileload', function (evt) : void
{
++loadedFiles;
const item = evt.item;
const id = (<any> stuffs.filter(obj => obj === item)[0]).id;
const result = evt.result;
(result instanceof Audio ?
WAVES :
PICTURES
)[id] = result;
}, false);
queue.loadManifest(stuffs);
}
}
I haven't found explanations for this. For now the appropriate solution I've found is to avoid the
private
access modifier forPROGRESS_BAR_WIDTH
andPROGRESS_BAR_HEIGHT
members, that is, let them be public.