Closed 8times12 closed 1 year ago
This is very cool. Since I am not a typescript user I do not know the right way to test this. What is the right way to add an automated test so that, if seedrandom is changed in the future, we can run the test to verify that the typescript declarations remain correct?
tsdlint is the testing tool and types/test.ts
contains type level test cases. run npm run tsdlint
to test.
@caasi Thank you for answering the question on my behalf.
@davidbau
As caasi said, I put a test file "type/test.ts" for linting the type declaration. The command npm run dtslint
of node package dtslint
helps you test it.
@8times12 Thank you for the types! Could you please give a quick example of importing and a call to seedrandom
in TypeScript? I tried but I kept getting an error when importing like this:
import { seedrandom } from 'seedrandom';
const rand = seedrandom('seed-value')();
console.log(rand);
Error:
const rand = seedrandom('seed-value')();
^
TypeError: seedrandom_1.seedrandom is not a function
FYI you can easily add this branch to a project with:
npm i git://github.com:8times12/seedrandom.git#typescript-declaration
For anyone having issues importing the package using import
, I was able to use the package like the following:
const seedrandom = require('seedrandom');
const seedValue = 'Hello!';
// Applies seed to generate random numbers from this value.
const random = seedrandom(seedValue);
// Random values:
console.log(random());
console.log(random());
console.log(random());
This could be an option with the right Babel config for Typescript apparently:
import seedrandom = require('seedrandom');
Hope this helps whilst the issue is being looked into! 🙏
I have created a simple type definition file with its linter. I think it would be useful to others, so if you'd like, could you merge it into your API? Best.