Skip to content
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

Typescript error when using require('emoji-regex') #102

Open
rabarrota opened this issue Oct 7, 2022 · 3 comments
Open

Typescript error when using require('emoji-regex') #102

rabarrota opened this issue Oct 7, 2022 · 3 comments

Comments

@rabarrota
Copy link

rabarrota commented Oct 7, 2022

I'm getting the following Intellisense error when using require('emoji-regex')

This expression is not callable.
  Type 'typeof import("emoji-regex")' has no call signatures.ts(2349)

Some context for how I'm using this:

const emojiRegex = require('emoji-regex');

...

const sanitizedText = text.replace(emojiRegex(), '');

This package works fine this way when actually being used. It just always shows this Typescript error.

Screen Shot 2022-10-07 at 11 15 46

@ghost
Copy link

ghost commented Dec 4, 2022

Interesting, I can't repro this, it works fine for me:

image

Do you think it's maybe because you're using require() instead of import?

Maybe because the type declaration module uses declare module { } it only works if you're using module-style imports?

Also what version of the package are you running?

@rabarrota
Copy link
Author

Yup, I'm assuming that's the problem. I'm using cjs so it doesn't look like the type declaration supports it.

I'm using 10.2.1

@vdh
Copy link

vdh commented Oct 19, 2023

The index.d.ts should be updated to this instead:

diff --git a/index.d.ts b/index.d.ts
index 6f57555090390e09a3b3a2e39bab037c995b47b9..beb73be29022bf20734057e38148282207f5fa2b 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,3 +1,4 @@
 declare module 'emoji-regex' {
-  export default function emojiRegex(): RegExp;
+  function emojiRegex(): RegExp;
+  export = emojiRegex;
 }

It looks like it was changed by #89 for the index.mjs file but that then broke types for the index.js file. With split files like this, it should probably be defined directly inside those files as JSDoc instead if they're going to vary in typing like that.

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

No branches or pull requests

2 participants