Add typings for function-demethodize #469
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think this is the last package that needed typings.
Currently there are 2 signatures you can call this with:
The best way to use this in my opinion is to specify the function typing on the variable you assign the function too, as such:
Unfortunately, you have to manually pass generics to this function in order to use it (unless you use the method shown directly above). This is because when you call
demethodize("".split)
typescript has no way of knowing what type you called the.split
method on.I wasn't able to get the generics working exactly how I wanted to, ideally, you would only have to specify the type that you are pulling the method from, and then it could auto infer the rest, eg;
Would infer the function signature
(p:string, a:string) => string[]
, however, I don't think that is currently possible because of the way that type inference works with default values for generics.Edit: I just noticed that my prettier config may have messed with the formatting of the files, I wasn't able to run eslint to format any typescript files. Seems like eslint is not configured to fix the typescript files.