-
-
Notifications
You must be signed in to change notification settings - Fork 420
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
Migrate codebase to Typescript #120
Conversation
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.
This looks great! 🎉
I've made some comments regarding how to make the transition seamless for current TypeScript users who have been using the DefinitelyTyped types.
tldr;
- Rename
IProps
toContentLoaderProps
- Re-export
IProps
from theindex.ts
top level file - Explicitly define all exported components as
FunctionComponent<IProps>
for a better type definition file.
Hope it all makes sense 😄
src/Holder.tsx
Outdated
width: 400, | ||
}; | ||
|
||
const InitialComponent = (props: IProps) => ( |
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.
Could this be typed as
import { FunctionComponent } from 'react';
// Or -> import { FC } from 'react' to save characters
const InitialComponent: FunctionComponent<IProps> = props => {
// ...
};
This way TS knows that this is a function component and auto injects the children
and ref
props for consumers.
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.
Isn't should be React.FunctionComponent
?
But great point
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.
You're right. I'm so used to using "esModuleInterop": true,
I forget it's not the default.
src/Holder.tsx
Outdated
import * as React from "react"; | ||
import Svg from "./Svg"; | ||
|
||
export interface IProps { |
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.
Perhaps this can be this be renamed to ContentLoaderProps
The current type definition file has used the above name.
This would mean that current TS users won't need to change their code once the updated library is published.
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.
Great point, but is it should start with I
which means a new interface?
I prefer to follow the tslint
recommendations than keep the oldest wrong version
Maybe we can update the current type definition as well
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.
Sure thing 👍
Perhaps with a deprecation warning.
src/Svg.tsx
Outdated
} & HolderProps | ||
import uid from "./uid"; | ||
|
||
export interface ISvgProps extends IProps { |
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.
If you define a component as a FunctionComponent
it doesn't need to declare children (unless you're expecting a render prop or restricting the type of children).
To enjoy this pattern you would need to name the default export.
import { FunctionComponent } from 'react';
const SomeName: FunctionComponent<IProps> = props => {
// ...
};
export default SomeName;
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.
Also, children
already exists in IProps
, so it isn't necessary, but let's keep you suggest
@@ -0,0 +1,9 @@ | |||
import Holder from "./Holder"; | |||
|
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.
Here would be a great place to re-export the IProps
or ContentLoaderProps
from ./Holder
.
That way users can use it in their own interfaces (all from the top level import).
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.
Great
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.
done
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.
@AjayPoshak thank you so much for your submission, it looks really great! 🥇
@ifiokjr I just leave my thought too, I hope you can contribute again :)
package.json
Outdated
"testonly": "cross-env NODE_ENV=test mocha $npm_package_options_mocha", | ||
"release:major": "npm run build && npm version major", | ||
"release:minor": "npm run build && npm version minor", | ||
"release:patch": "npm run build && npm version patch", | ||
"lint": "eslint 'src/**/*.js'", | ||
"flow": "flow", | ||
"watch": "node_modules/.bin/tsc --watch", |
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 would be better to say what this script is watching, like:
"tsc": "node_modules/.bin/tsc",
"tsc:watch": "npm run tsc -- --watch",
src/Holder.tsx
Outdated
import * as React from "react"; | ||
import Svg from "./Svg"; | ||
|
||
export interface IProps { |
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.
Great point, but is it should start with I
which means a new interface?
I prefer to follow the tslint
recommendations than keep the oldest wrong version
Maybe we can update the current type definition as well
src/Holder.tsx
Outdated
import Svg from "./Svg"; | ||
|
||
export interface IProps { | ||
rtl?: boolean; |
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.
- Actually, all props are not required;
- Please sort the lines by alphabetical
src/Holder.tsx
Outdated
secondaryColor?: string; | ||
secondaryOpacity: number; | ||
children?: React.ReactNode; | ||
preserveAspectRatio?: string; |
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.
Please update this value:
preserveAspectRatio?: 'none' | 'xMinYMin meet' | 'xMidYMin meet' | 'xMaxYMin meet' | 'xMinYMid meet' | 'xMidYMid meet' | 'xMaxYMid meet' |
'xMinYMax meet' | 'xMidYMax meet' | 'xMaxYMax meet' | 'xMinYMin slice' | 'xMidYMin slice' | 'xMaxYMin slice' | 'xMinYMid slice' |
'xMidYMid slice' | 'xMaxYMid slice' | 'xMinYMax slice' | 'xMidYMax slice' | 'xMaxYMax slice';
src/Holder.tsx
Outdated
secondaryOpacity: number; | ||
children?: React.ReactNode; | ||
preserveAspectRatio?: string; | ||
style: { [key: string]: 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.
Please, update to this value:
style?: React.CSSProperties;
src/stylized/BulletListStyle.tsx
Outdated
|
||
export default BulletListStyle | ||
export default BulletListStyle; |
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.
Please apply these changes in the others components
tslint.json
Outdated
{ | ||
"defaultSeverity": "error", | ||
"extends": [ | ||
"tslint:recommended" |
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.
Add the tslint-config-prettier
to work fine with prettier
package.json
Outdated
"testonly": "cross-env NODE_ENV=test mocha $npm_package_options_mocha", | ||
"release:major": "npm run build && npm version major", | ||
"release:minor": "npm run build && npm version minor", | ||
"release:patch": "npm run build && npm version patch", | ||
"lint": "eslint 'src/**/*.js'", | ||
"flow": "flow", | ||
"watch": "node_modules/.bin/tsc --watch", |
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.
Missing tslint
dependency and script.
Once added the tslint
you can remove eslint
stuff
package.json
Outdated
"rollup-plugin-uglify": "^6.0.0" | ||
"rollup-plugin-typescript2": "^0.18.0", | ||
"rollup-plugin-uglify": "^6.0.0", | ||
"ts-node": "^7.0.1", |
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.
why exactly we need this?
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.
removed, it was needed to run mocha_test runner, but now as we have moved to jest as test runner, so we don't need it. We are using ts-jest
now.
src/Svg.tsx
Outdated
uniquekey, | ||
width, | ||
preserveAspectRatio, | ||
// tslint:disable-next-line:trailing-comma |
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.
Is it really necessary? I think with the suggestion in the tslint
that I did, it'll be solved
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.
done
Really thanks @AjayPoshak for your contribution! -- You just need to resolve the conflicts, then I can merge into Again, thanks a lot 🎉 |
@danilowoz Cool will do it. |
I am migrating tests to typescript as well. This may take some time. Hopefully, I'll complete it by tomorrow. |
Codecov Report
@@ Coverage Diff @@
## develop #120 +/- ##
======================================
Coverage 100% 100%
======================================
Files 8 9 +1
Lines 23 61 +38
Branches 4 7 +3
======================================
+ Hits 23 61 +38
Continue to review full report at Codecov.
|
const ids = new Array(options).fill(" ").map(item => uid()) | ||
// @ts-ignore To avoid adding polyfill for `from` |
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.
To use ES6 features in this file like fill
, from
, Set
, we have to add polyfills. As this is just a test file, not affecting our library consumer in any way. So I added @ts-ignore
to ignore these ts
errors.
@danilowoz @ifiokjr I have made requested changes. Please review. |
* Ignore rpt2_cache * Add typescript pkg; Add tsc runner script * Replace babel with ts compiler * Typescript configs * Update lockfile * Convert Holder to tsx * Convert svg to tsx * Convert index.js to ts * Convert uid to ts * Convert BulletListStyle to tsx * Convert CodeStyle to tsx * Convert FacebookStyle to tsx * Convert InstagramStyle to tsx * Convert ListStyle to tsx * Remove flow preset * Add ts-node for ts execustion env for nodejs * Remove flow preset & rollup-babel plugin; Add ts-node for ts env in nodejs * Update lockfile * Update watch script for tsc * Rename IProps to IContentLoaderProps; Use FC for validation * Remove unwanted ISvgProps; import IContentLoaderProps for type validations * import and re-export IContentLoaderProps for better types * Import and use types from IContentLoaderProps * Remove eslint; replaced by tslint and tslint-prettier * Add tslint-config-prettier * Implement stricter type checking * Remove comments as it is handled by tslint-config-prettier now * Replace lint by tsc * remove eslint and flow configs * Add style default props * Add jest options to include ts test files * Add options to load json file * Migrate tests from JS to TS for better interoperability * Updated snapshots * Remove ts-node * Break line after react import * Remove export from bottom of file and move to component definition BREAKING CHANGE: Migrate codebase to typescript Closes #120
* test(Refactor): (#117) * test(Refactor): * Holder / SVG tests * Svg tests * Removed old tests * Coverage * Migrate to travis * Update travis * Update travis * ci(Release): * test(package): * ci(Travis): * chore(devDependencies): Package to generate the changelog * feat(Codebase): Format * feat(Types): Export types * ci(Build step): * feat(RTL): Flip the content BREAKING CHANGE: Flip all content instead of only flip the animation direction Closes #122 * Migrate codebase to Typescript (#120) * Ignore rpt2_cache * Add typescript pkg; Add tsc runner script * Replace babel with ts compiler * Typescript configs * Update lockfile * Convert Holder to tsx * Convert svg to tsx * Convert index.js to ts * Convert uid to ts * Convert BulletListStyle to tsx * Convert CodeStyle to tsx * Convert FacebookStyle to tsx * Convert InstagramStyle to tsx * Convert ListStyle to tsx * Remove flow preset * Add ts-node for ts execustion env for nodejs * Remove flow preset & rollup-babel plugin; Add ts-node for ts env in nodejs * Update lockfile * Update watch script for tsc * Rename IProps to IContentLoaderProps; Use FC for validation * Remove unwanted ISvgProps; import IContentLoaderProps for type validations * import and re-export IContentLoaderProps for better types * Import and use types from IContentLoaderProps * Remove eslint; replaced by tslint and tslint-prettier * Add tslint-config-prettier * Implement stricter type checking * Remove comments as it is handled by tslint-config-prettier now * Replace lint by tsc * remove eslint and flow configs * Add style default props * Add jest options to include ts test files * Add options to load json file * Migrate tests from JS to TS for better interoperability * Updated snapshots * Remove ts-node * Break line after react import * Remove export from bottom of file and move to component definition BREAKING CHANGE: Migrate codebase to typescript Closes #120
🎉 This issue has been resolved in version 4.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
Moved codebase to Typescript from Flow JS. TS is fun so far 💯
Related Issue #[issue number]
Related Issue #111
Any Breaking Changes
Nope, It won't impact end user
Checklist