I just started taking a look at Typescript and have an issue when playing around.
I want to write a library to manage a general tree structure and just doing some very basic tests to see how TS works.
Start of the simple setup with 3 files:
- GForest.ts
- GTree.ts
- GNode.ts
Currently, GForest.ts:
import * as Immutable from "immutable";
import GTree from "./GTree";
export default class Forest{
public static createTree(){
let tree = new GTree();
}
}
GTree.ts:
export default class GTree{
constructor(){
console.log("Tree constructed");
}
public static createNode(){
}
}
I created a simple test.js file to call the library (compiled TS to ES5):
var GForest = require("./build/GForest");
console.log(GForest);
When running
> node test
The output is:
I don't understand why the result is:
{ default: { [Function: Forest] createTree: [Function] } }
Why is there an object with default as key and how do I change this to achieve desired behaviour?
Because of this, I'm unable to just call:
GForest.createTree();
(I want to expose the creation of a tree through a static factory) Any help?
var GForest = require("./build/GForest");insidetest.jsinstead ofimportand then compiling the file to js?