-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Generator Types #79
Comments
I have the same problem. Anyone know how we should handle it? |
edit: Nevermind. This doesn't work. I can't get the typescript compiler to accept custom types without hacking the casual index.d.ts.
|
This is how I worked around it to add import * as casual from 'casual';
interface Generators extends Casual.Generators {
_oneOf: <T>(values: T[]) => T;
functions(): functions;
}
interface functions extends Casual.functions {
oneOf: <T>(values: T[]) => T;
}
const extendedCasual = casual as Generators & Casual;
const testVar = extendedCasual._oneOf(config.contentTypes); |
Hey all, is the above workaround still the best option for this? Has this been looked into from the maintainer? |
My workaround was to simply create a function which returned the generated data that I am interested in. For example, the generateValidPassword function takes in a length (or default 8) and will return a random string of letters between that passed number and 3x that amount.
When trying to define this as a generator, TS would give me an error but as a normal function TS is fine with it. Hope this helps someone. |
I am relatively new to Typescript and I have been trying to read the most appropriate way to extend the current types available on Casual to accomodate custom generators. For example:
But whatever I try does not seem to work?
Does anyone have experience extending the current
index.d.ts
?The text was updated successfully, but these errors were encountered: