Skip to content

added ts definitions #29

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

added ts definitions #29

wants to merge 5 commits into from

Conversation

Akim95
Copy link

@Akim95 Akim95 commented Oct 2, 2019

feel free to contribute and keep it improving!

@davisjam
Copy link
Owner

davisjam commented Oct 6, 2019

Hi @Akim95, thanks for the contribution.

I haven't used TS before.

Can you clarify for me the maintenance burden this would introduce if I were to modify the API? Is the TS file automatically updated or would new PRs need to update it if they changed the API?

index.d.ts Outdated
limit: number;
}

declare function safeRegex<T>(regex: RegExp, opts?: Options | T): void;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • currently the safeRegex function takes RegExp's ,strings and anything with a toString method in its re parameter (so technically any, I guess). Which'd make this declaration a bit too restrictive.
  • this definition seems to have void as a return type - but the function currently returns a boolean (A void return type would've been correct if safeRegex would've been implemented as a function that threw an exception in case of problems and silently exited in all other cases).
  • I see you're using a generic (the <T> & T in the declaration - had to look that one up) why is that?

@Akim95
Copy link
Author

Akim95 commented Oct 7, 2019

Hi @Akim95, thanks for the contribution.

I haven't used TS before.

Can you clarify for me the maintenance burden this would introduce if I were to modify the API? Is the TS file automatically updated or would new PRs need to update it if they changed the API?

Need a new PRs but no need to worry if you have any API need to change because people that using this package with Typescript will taking care of it.

@@ -4,6 +4,6 @@ interface Options {
limit: number;
}

declare function safeRegex<T>(regex: RegExp, opts?: Options | T): void;
declare function safeRegex<T>(regex: RegExp | string | T, options?: Options): boolean;
Copy link

@sverweij sverweij Oct 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The union for the regex with RegExp and string is an improvement 👍
  • Could you explain how the generic (the <T> and the T in union of the first parameter) relates to the original function? The declaration without it (export function safeRegex (regex: RegExp | string | any, options?: Options): boolean) seems to match the original function just as well, but I might've missed some thing.

@MarcusOtter
Copy link

For the record, I believe most people are using the definitions in DefinitelyTyped for this package.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/safe-regex/index.d.ts

@ImRodry
Copy link

ImRodry commented Oct 24, 2022

Just found this package recently and I'd like to use it with TS definitions. Are there plans to keep this PR up to date and merge it? I can open a new one if the original author isn't available anymore @davisjam

@davisjam
Copy link
Owner

davisjam commented Nov 1, 2022 via email

@ImRodry
Copy link

ImRodry commented Nov 1, 2022

It looks like this PR has conflicts and the author hasn't been too active. I'll try to open a new one and make sure that it's up to date!

@davisjam
Copy link
Owner

davisjam commented Nov 1, 2022 via email

@ImRodry
Copy link

ImRodry commented Nov 1, 2022

Opened the new, up-to-date, PR at #52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants