Skip to content

Use TS generics to improve random_element return typeΒ #115

@TSMMark

Description

@TSMMark

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch casual@1.6.2 for the project I'm working on.

Some of the functions could easily have their TS types improved by using generics.

Here is the diff that solved my problem:

diff --git a/node_modules/casual/index.d.ts b/node_modules/casual/index.d.ts
index b556860..b0098e5 100644
--- a/node_modules/casual/index.d.ts
+++ b/node_modules/casual/index.d.ts
@@ -282,7 +282,7 @@ declare namespace Casual {
     define(type: string, cb: (...args: any[]) => any): void;
 
     // HELPERS
-    random_element(elements: Array<any>): any;
+    random_element<T>(elements: Array<T>): T;
     random_value(obj: Object): any;
     random_key(obj: Object): any;
     populate(str: string): string;

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions