I'd trying to add seedrandom to an angular project. I have installed it and typescript definitions using npm. My package json has the relevant entries (below) so im confident it installed ok, and the relevant folders are in node-modules.
"dependencies": {
"@types/seedrandom": "^2.4.28",
"seedrandom": "^3.0.5"
}
Despite this, I persistently get the error: "Property 'seedrandom' does not exist on type 'Math'."
In fact, when I do ng serve
the error throws in the console, but the web app works fine. When I do ng build
I get the error and the build fails.
I've tried defining an interface per this but doesn't help. And I've stared at the code for two days too, that didn't help either.
getRandomNumber(n) {
const randomNumber = new Math.seedrandom( '1234' );
return Math.round( Math.round( randomNumber() * n) );
}
UPDATE: Following the answer from Myk I tried the following:
import { seedrandom } from 'seedrandom';
getRandomNumber(n) {
const randomNumber = seedrandom( '1234' );
return Mathround( Math.round( randomNumber() * n) );
}
only get error: Module '"../blah/node_modules/@types/seedrandom"' has no exported member 'seedrandom'.
Which is interesting because when I checked the @types/seedrandom/index.d.ts file is include the lines:
export = seedrandom;
export as namespace seedrandom;
How do I get seedrandom working in Angular??