mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
clean up randomWords signature
This commit is contained in:
parent
1e807c741e
commit
67b4a05878
@ -315,6 +315,10 @@ type RandomWordsOptions = {
|
|||||||
join?: string;
|
join?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type RandomWordsResult<T extends RandomWordsOptions> = T extends { join: string }
|
||||||
|
? string
|
||||||
|
: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate one or more random words.
|
* Generate one or more random words.
|
||||||
*
|
*
|
||||||
@ -325,11 +329,9 @@ type RandomWordsOptions = {
|
|||||||
*
|
*
|
||||||
* @returns An array of words or a single string, depending on parameter choices.
|
* @returns An array of words or a single string, depending on parameter choices.
|
||||||
*/
|
*/
|
||||||
export function randomWords<T extends RandomWordsOptions>(
|
export function randomWords<T extends RandomWordsOptions>(opts: T) {
|
||||||
opts: T
|
|
||||||
): T extends { join: string } ? string : string[] {
|
|
||||||
// there is a type incompatibility here because `random-words` uses overloads rather than generics
|
// there is a type incompatibility here because `random-words` uses overloads rather than generics
|
||||||
return rw(opts) as any;
|
return rw(opts) as RandomWordsResult<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Box-Muller transformation for a random sample from normal distribution with mean = 0, std = 1
|
// Box-Muller transformation for a random sample from normal distribution with mean = 0, std = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user