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

chore: add typescript definitions #346

Merged
merged 3 commits into from Feb 6, 2021

Conversation

connor4312
Copy link
Contributor

Adding TypeScript definitions will make astring easier to use by people writing their apps in TypeScript.

If you don't want these in the package, they can also be published to DefinitelyTyped, but having them bundled makes life easier for consumers.

@codecov
Copy link

codecov bot commented Aug 29, 2020

Codecov Report

Merging #346 (4722d2a) into master (f1798f5) will increase coverage by 0.51%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #346      +/-   ##
==========================================
+ Coverage   94.97%   95.48%   +0.51%     
==========================================
  Files           1        1              
  Lines        1134      554     -580     
==========================================
- Hits         1077      529     -548     
+ Misses         57       25      -32     
Impacted Files Coverage Δ
src/astring.js 95.48% <0.00%> (+0.51%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f1798f5...cb4af12. Read the comment docs.

@davidbonnet
Copy link
Owner

Thanks @connor4312 for these types, which are more complete than the one published on DefinitelyTyped: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/astring/index.d.ts
I'll review them soon.

@davidbonnet davidbonnet changed the title add typescript definitions chore: add typescript definitions Jan 3, 2021
@davidbonnet davidbonnet merged commit a94cc7b into davidbonnet:master Feb 6, 2021
davidbonnet pushed a commit that referenced this pull request Feb 6, 2021
* However, if an `output` stream is provided in the `options`, it writes to that stream and returns it.
*/
export function generate(node: Node, options?: Options<null>): string
export function generate(node: Node, options?: Options<Writable>): Writable
Copy link
Contributor Author

@connor4312 connor4312 Feb 6, 2021

Choose a reason for hiding this comment

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

This overload looks slightly questionable to me. It works because of the order of declarations, but because output is optional {} satisfies both Options<null> and Options<Writable>. To reduce ambiguity I would remove output from the options and then write this as:

export function generate(node: Node, options?: Options): string
export function generate(node: Node, options: Options & { output: Writable }): Writable

Copy link
Owner

Choose a reason for hiding this comment

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

How about this?

export interface Options<Output = null | undefined> {
// …
export function generate(node: Node, options?: Options): string
export function generate(node: Node, options: Options<Writable>): Writable

@connor4312
Copy link
Contributor Author

Thanks for the merge!

@connor4312 connor4312 deleted the typescript branch February 6, 2021 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants