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 declarations to @svgr/core #555

Merged
merged 4 commits into from Sep 19, 2021

Conversation

nirtamir2
Copy link
Contributor

@nirtamir2 nirtamir2 commented May 8, 2021

Summary

Following #513 I added TypeScript declaration file (index.d.ts) to @svgr/core with @jschaf #513 (comment) modified a little.
This will help for easier auto-completion and for other library authors that use TypeScript and want to pass type-safe params to @svgr/core

NOTICE: as #513 (comment) notes - the types are not 100% compatible but I think for most people it will be good enough (and it can improve it over time).

Test plan

I use https://github.com/ai/check-dts for checking .d.ts files

  • index.types.ts shows positive tests
  • index.errors.ts includes improper usage of the library

I added it to the CI too.

image

image

@vercel
Copy link

vercel bot commented May 8, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/gregberge/svgr/5RJ1ijqgdectcLbeyxCVVtjmeDSH
✅ Preview: https://svgr-git-fork-nirtamir2-add-typescript-declarations-gregberge.vercel.app

@codecov
Copy link

codecov bot commented May 8, 2021

Codecov Report

Merging #555 (12cb449) into main (aaddbd1) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #555   +/-   ##
=======================================
  Coverage   91.39%   91.39%           
=======================================
  Files          31       31           
  Lines        1081     1081           
  Branches      333      333           
=======================================
  Hits          988      988           
  Misses         88       88           
  Partials        5        5           

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 aaddbd1...12cb449. Read the comment docs.

@nirtamir2 nirtamir2 changed the title Add typescript declarations Add TypeScript declarations to @svgr/core May 8, 2021
export { default as File } from './File'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My IDE complains about it - so I change it.
Is it ok?

Comment on lines +8 to +9
"ci": "yarn build && yarn lint && yarn check-dts && yarn test --ci --coverage && codecov",
"check-dts": "check-dts",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added check-dts to the ci script

@@ -0,0 +1,10 @@
import svgr from './'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

index.d.ts negative test

@@ -0,0 +1,15 @@
import svgr from './'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

index.d.ts positive test

@@ -0,0 +1,10 @@
import svgr from './'

// THROWS Argument of type 'null' is not assignable to parameter of type 'string'.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The TS compiler error message

@nirtamir2 nirtamir2 marked this pull request as ready for review May 8, 2021 15:55
@rnarcos
Copy link

rnarcos commented Jun 8, 2021

Can this be merged yet?

@nirtamir2
Copy link
Contributor Author

nirtamir2 commented Jun 8, 2021

I'm not this project maintainer, but from my side this PR is ready. I added the comments to make the review easier

}

type ConvertT = {
(svgCode: string, opts?: SvgrOpts, state?: TemplateData): Promise<void>
Copy link

Choose a reason for hiding this comment

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

I'm still spinning up on svgr, but isn't a Promise<string> returned?


type ConvertT = {
(svgCode: string, opts?: SvgrOpts, state?: TemplateData): Promise<void>
sync: (svgCode: string, opts?: SvgrOpts, state?: TemplateData) => void

Choose a reason for hiding this comment

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

I believe this sync function returns string with svg code, instead of void.

Suggested change
sync: (svgCode: string, opts?: SvgrOpts, state?: TemplateData) => void
sync: (svgCode: string, opts?: SvgrOpts, state?: TemplateData) => string


export interface SvgrOpts {
/** Specify a custom config file. */
configFile?: string

Choose a reason for hiding this comment

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

I think this object can also have the plugins attribute

/** Specify custom plugins installed. */
plugins?: string[];


Screen Shot 2021-09-16 at 21 36 11

@gregberge
Copy link
Owner

Thanks, will try to rewrite everything in TypeScript, but I think I will make a release before that includes typings.

@gregberge gregberge merged commit 681303a into gregberge:main Sep 19, 2021
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.

None yet

5 participants