mathiasbynens / emoji-regex

A regular expression to match all Emoji-only symbols as per the Unicode Standard.
https://mths.be/emoji-regex
MIT License
1.73k stars 174 forks source link

Adding TS typings. #42

Closed Fazendaaa closed 5 years ago

Fazendaaa commented 5 years ago

I've been using your awesome package with TypeScript. This is my types definitions, I would love to share it.

mathiasbynens commented 5 years ago

As a TypeScript n00b, could you please explain the benefit of including this in the repo? Is the intention to add it to the npm package as well? In that case, the files property in package.json should be updated.

Fazendaaa commented 5 years ago

The main advantage of adding the TS typings is that in a TS environment where the user has intellisense, this makes it more productive to know what the package does and what the parameters and functions are, almost like a JSDocs with steroids.

Besides that, with the use of linters they can end up telling the user that this dependency cannot be verified if the TS typings are missing, throwing it as a warning -- just as example, I have a pre-commit hook that runs my linter and it was giving me this warning until I created this typing to this package.

And yes, the npm package must be updated to this changes be usable to the user. I will look into the files property in the package.json.

henrikra commented 5 years ago

Would be nice to have TS types in the library as for example Redux is doing https://github.com/reduxjs/redux/blob/master/index.d.ts

henrikra commented 5 years ago

Btw tested this locally and it works 🎉 @Fazendaaa

Fazendaaa commented 5 years ago

Thanks, @henrikra. But last week I discovered "tsd-check", need to improve this. If @mathiasbynens have any interest in it, I can improve the typings.

henrikra commented 5 years ago

Other option that we merge this so every one get benefit of types quickly and you can make another pr about tsd-check :)

henrikra commented 5 years ago

@mathiasbynens Can we merge this?

henrikra commented 5 years ago

@mathiasbynens Can you make release out of this so people can actually use this? :D

mathiasbynens commented 5 years ago

@henrikra Done.

henrikra commented 5 years ago

@mathiasbynens I tried version 7.0.2 and the types are not included aka they are not working. See from the picture. @Fazendaaa Is something removing src folder before publishing? At least common way I see is that types should be in the root folder of the library and not in src folder

image

mathiasbynens commented 5 years ago

Oh yeah, "files" is set to "index.d.ts" but "types" points to the file in src, where it’s actually located. package.json should be fixed and the file should be moved. PR welcome :)

henrikra commented 5 years ago

@mathiasbynens PR opened https://github.com/mathiasbynens/emoji-regex/pull/51