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

Add typescript definition #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dderevjanik
Copy link

@dderevjanik dderevjanik commented Apr 20, 2018

Hi,

I would like to contribute with typescript definition file (index.d.ts) to project.

There's no typings in DefinetelyTyped and TS project has to create their own d.ts everytime. So, instead of creating PR to DefinitelyTyped, it makes more sense to create PR directly to this Repo, because repo wasn't updated for a while and it is not going (probably) to change API.

Several IDEs would also benefits from this and they will be able to provide intellisense for user. This is not only exclusive for Typescript devs but it could be used for JS aswell.

@jskrnbindra
Copy link

Ya adding typings can be a great help.

*/
declare function fuzzysearch(needle: string, haystack: string): boolean;

export = fuzzysearch;
Copy link

@jskrnbindra jskrnbindra Apr 30, 2018

Choose a reason for hiding this comment

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

I think

export default fuzzysearch;

would be better here.
@dderevjanik

Copy link
Author

Choose a reason for hiding this comment

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

I tried it, but now I'm getting this error

[ts] Cannot invoke an expression whose type lacks a call signature. Type 'typeof 'fuzzysearch'' has no compatible call signatures.

export = fuzzysearch works as expected.

Choose a reason for hiding this comment

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

@jskrnbindra @dderevjanik Without the empty namespace but with the default export it should work.
The default export would match the libraries real export, I think.

Copy link

Choose a reason for hiding this comment

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

As weird as it looks, these typings are correct as-is. (It matches the underlying implementation of module.exports = fuzzysearch;)

Writing the types as a default export would work in some cases but not others, depending on which module loader a given project is using. Would love to see this get merged! 🙏

@dderevjanik
Copy link
Author

@bevacqua Please, is there something I can do better or different to make this PR merged ? Thanks

@chenyong
Copy link

What happened to this issue?

@dderevjanik
Copy link
Author

still waiting for response

@chenyong
Copy link

hello? @bevacqua

@remcohaszing
Copy link

FWIW I created @types/fuzzysearch before I noticed this PR. It’s effectively the same.

@jskrnbindra
Copy link

jskrnbindra commented Apr 4, 2023

Sorry folks. I don't remember reviewing this PR. Nor do I have write permissions on this repo.

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.

6 participants