-
-
Notifications
You must be signed in to change notification settings - Fork 421
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
feature(typescript): add typescript to svgr/core [WIP] #130
Conversation
@neoziro No sorry It's good, I did a yarn build and it created a lib directory with tests files, so when I run jest, it tries to exec the tests in the lib directory, so I have to delete it and now it works :) |
@marquesdev it looks great! Ping me when it is done (documentation). |
Codecov Report
@@ Coverage Diff @@
## master #130 +/- ##
==========================================
- Coverage 88.55% 86.66% -1.89%
==========================================
Files 26 27 +1
Lines 428 465 +37
Branches 113 127 +14
==========================================
+ Hits 379 403 +24
- Misses 37 51 +14
+ Partials 12 11 -1
Continue to review full report at Codecov.
|
packages/cli/src/index.js
Outdated
@@ -119,6 +120,8 @@ async function run() { | |||
} | |||
} | |||
|
|||
if(config.typescript) config.ext = "ts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks here, like we are forcing the ".ts" extension on typescript parsing which makes perfect sense, however some people prefer using ".tsx" instead. I would recommend something in the line of:
if(config.typescript && !config.ext) config.ext = "ts";
to make sure that the user still manually can override the extension.
(if this is already covered, then i'm sorry about the interruption)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thks for the help :)
} else if (opts.titleProp && opts.ref) { | ||
props = '{svgRef: string, title: string}' | ||
} else if (opts.expandProps) { | ||
props = 'props: any' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had great success here, typing the props as SVGAttributes<SVGElement>
imported with import React, { SVGAttributes } from 'react';
instead of any
type.
Mind though, that you would then need to create a few union types for the cases above, such as {svgRef, ...props}: SVGAttributes<SVGElement> & {svgRef: string}
added a few comments, hope it's okay. 🙂 |
Also what about using React Native + TypeScript. @JReinhold do you know if it is common to use TypeScript + React Native? Should we support it? |
I don't have any numbers, but my gut feeling says that the React Native+TypeScript combo has almost the same usage as the React+TypeScript combo, since the benefits and hurdles of TS are the exact same across React/React Native. So yes, I would suggest to support RN as well. Could be in a second PR though. |
Yes but it is pretty confusing for users that if I use |
I see. Agree! |
Outdated, we restart from scratch on it. |
@neoziro Hello !
Really good job for the refacto :)
I have a problem with svgr/cli, I want to run the tests of the
index.test.js
but I have this error message :I tried to run
yarn build
but it not fix this, any idea ?