feat: infer result type correctly with TypeScript #142
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.
Greetings, it looks like some people (#126 for example) want the type definition to support the non-string results, and here is my contribution.
Basically I added the minimal fix to the type definition to infer the result type based on the output option, and the TypeScript test cases to validate the type checks successfully pass as intended. As long as the output option is statically known to the compiler (which hopefully would be the case in the typical use cases), the result type can be uniquely determined; otherwise, the applications are still responsible for asserting the expected type but they no longer need to insert the dirty
as unknown
at least.I also removed the mention to DefinitelyTyped in the doc comment and the type definition generaiton script in package.json since they looked obsolete.
Hope this helps. Thank you very much.