Closed twpage closed 4 years ago
Hi @twpage,
the RNG class is indeed not exported. I think this was also the behavior pre-TS, so in order to create a separate instance, you just had to clone()
the existing ROT.RNG singleton.
I am, however, not sure what is the main problem here. If you need to pass your own RNG instances around and need a proper typing, perhaps this might work?
function doStuff(x: typeof ROT.RNG) {
alert(x.getUniform());
}
Using typeof works. I knew there was a more elegant way I just could not figure it out. I appreciate the quick response as always! I love the library - especially loving the full fledged typescript version.
Great! Glad to be of help.
I have been using typescript since before rot.js converted so now I am unwinding a lot of my various 'hacks'. I am running into trouble accessing the underlying RNG class in the default index.d.ts. It seems like all that is exported is the actual RNG object (default RNG), whereas I am using multiple RNG objects, and have some code around accessing them. Since these functions return an RNG as a type ('RNGable' previously... maybe this was from the old @types/rot-js) I need to access the underlying class.
I modified rng.d.ts to change the class name to 'RNGable' and export it:
export declare class RNGable {
now I can do code like this:
function getRNG(rng_type: RngType, level_id: number = null) : RNGable {
Is there a more elegant way I should be doing this? Thanks!