Skip to content

feat: Add typescript declaration file #177

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

Merged
merged 1 commit into from
Apr 8, 2021
Merged

Conversation

dmaccormack
Copy link
Collaborator

No description provided.

@dmaccormack dmaccormack added the enhancement New feature or request label Apr 8, 2021
@dmaccormack dmaccormack self-assigned this Apr 8, 2021
@dmaccormack
Copy link
Collaborator Author

Closes #97

@dmaccormack
Copy link
Collaborator Author

Closes #165

@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 8, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@dmaccormack dmaccormack linked an issue Apr 8, 2021 that may be closed by this pull request
@dmaccormack dmaccormack mentioned this pull request Apr 8, 2021
@dmaccormack dmaccormack merged commit 13f1fd4 into master Apr 8, 2021
@darcyparker
Copy link

Looks good. Thanks for adding typescript definitions.

The only thing I noticed... (a nitpick) is that while type JsonURLStringifyOptions = {...} is valid, usually it is written as interface JsonURLStringifyOptions { ... }. JsonURLParseOptions shares many properties... so you could have defined a base interface and used extends.

Regardless... this is useable and I appreciate having typescript definitions now.

@dmaccormack
Copy link
Collaborator Author

The only thing I noticed... (a nitpick) is that while type JsonURLStringifyOptions = {...} is valid, usually it is written as interface JsonURLStringifyOptions { ... }. JsonURLParseOptions shares many properties... so you could have defined a base interface and used extends.

OK, good to know. I used this a reference:
https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#differences-between-type-aliases-and-interfaces

Is the preference for interface an idiom?

While JsonURLParseOptions and JsonURLStringifyOptions do indeed share many property names, the value types sometimes differ, and the documentation is written from the POV of parse() and stringify(), respectively. That's why I chose to model them as distinct types.

@darcyparker
Copy link

The referenced you used is good. And it gives good examples comparing how a type vs interface can be extended. If an interface is chosen, it sometimes makes reading error messages clearer. But I don't think it really matters here because these types have a simple structure. I suppose interface is just a pattern I am used to seeing more and it struck me as different even though I don't have a good reason to say one is better than the other here.

If you think they are sufficiently distinct and that if you ever have to change some property it will only effect parse() or only stringify() and not both, then I think using type is a good. Maybe just keep it in the back in your mind so that if in the future you find your editing the same property in 2 places, maybe its worth extracting a common interface between the two.

@jsonurl jsonurl deleted the feat-typescript-defs branch April 13, 2021 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript support
2 participants