Within my main.ts file:
import { App } from './app';
import './styles.scss';
ready(new App().init);
function ready(fn) {
if (document.readyState !== 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
I also have an app.ts file:
export class App {
constructor() {
}
private print = (str: string) => console.log(str);
init(){
this.print('test');
}
}
Upon running this setup with the ts-loader in webpack, using a tsconfig.json that looks like this:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"lib": ["es5", "dom", "es2015.iterable"]
}
}
An error occurs: Uncaught TypeError: this.print is not a function at HTMLDocument.App.init (app.ts:17)
Attempts were made to define the method as private print(str){ console.log(str); }, but unfortunately, this did not resolve the issue.
Is there any way to ensure that the method call within the init() function works correctly?
EDIT: I forgot to mention, I am utilizing webpack v. 1.14.0 and TypeScript 2.1.5 (also tested with 2.1.4).