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

Migrate codebase to Typescript #120

Merged
merged 39 commits into from
Jan 2, 2019

Conversation

AjayPoshak
Copy link
Contributor

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

  • Are all the test cases passing?
  • If any new feature has been added, then are the test cases updated/added?
  • Has the documentation been updated for the proposed change, if required?

Copy link

@ifiokjr ifiokjr left a 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 to ContentLoaderProps
  • Re-export IProps from the index.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) => (
Copy link

@ifiokjr ifiokjr Dec 3, 2018

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.

Copy link
Owner

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

Copy link

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 {
Copy link

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.

Copy link
Owner

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

Copy link

@ifiokjr ifiokjr Dec 3, 2018

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 {
Copy link

@ifiokjr ifiokjr Dec 3, 2018

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;

Copy link
Owner

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";

Copy link

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).

Copy link
Owner

Choose a reason for hiding this comment

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

Great

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Owner

@danilowoz danilowoz left a 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",
Copy link
Owner

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 {
Copy link
Owner

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;
Copy link
Owner

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;
Copy link
Owner

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 };
Copy link
Owner

@danilowoz danilowoz Dec 3, 2018

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;


export default BulletListStyle
export default BulletListStyle;
Copy link
Owner

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"
Copy link
Owner

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",
Copy link
Owner

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",
Copy link
Owner

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?

Copy link
Contributor Author

@AjayPoshak AjayPoshak Dec 23, 2018

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
Copy link
Owner

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@danilowoz danilowoz changed the base branch from master to develop December 17, 2018 18:52
@danilowoz
Copy link
Owner

Really thanks @AjayPoshak for your contribution!

--

You just need to resolve the conflicts, then I can merge into develop. Don't worry if you don't know what changes it should to keep, I'll check it before I release a new version, if there is any doubt, keep your changes. About the yarn.lock you can remove the content, I can remake it later.

Again, thanks a lot 🎉
Let's move this amazing community ⚛️

@AjayPoshak
Copy link
Contributor Author

AjayPoshak commented Dec 18, 2018

@danilowoz Cool will do it.

@AjayPoshak
Copy link
Contributor Author

I am migrating tests to typescript as well. This may take some time. Hopefully, I'll complete it by tomorrow.

@codecov
Copy link

codecov bot commented Dec 23, 2018

Codecov Report

Merging #120 into develop will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           develop   #120   +/-   ##
======================================
  Coverage      100%   100%           
======================================
  Files            8      9    +1     
  Lines           23     61   +38     
  Branches         4      7    +3     
======================================
+ Hits            23     61   +38
Impacted Files Coverage Δ
src/uid.ts 100% <ø> (ø)
src/Holder.tsx 100% <100%> (ø)
src/stylized/BulletListStyle.tsx 100% <100%> (ø)
src/index.ts 100% <100%> (ø)
src/stylized/CodeStyle.tsx 100% <100%> (ø)
src/Svg.tsx 100% <100%> (ø)
src/stylized/ListStyle.tsx 100% <100%> (ø)
src/stylized/FacebookStyle.tsx 100% <100%> (ø)
src/stylized/InstagramStyle.tsx 100% <100%> (ø)
... and 2 more

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 89afd31...5a12912. Read the comment docs.

const ids = new Array(options).fill(" ").map(item => uid())
// @ts-ignore To avoid adding polyfill for `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.

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.

@AjayPoshak
Copy link
Contributor Author

AjayPoshak commented Dec 23, 2018

@danilowoz @ifiokjr I have made requested changes. Please review.
@danilowoz please generate yarn.lock after merging. I haven't updated lockfile.

@danilowoz danilowoz merged commit 2254f25 into danilowoz:develop Jan 2, 2019
@danilowoz danilowoz mentioned this pull request Jan 3, 2019
danilowoz pushed a commit that referenced this pull request Jan 3, 2019
* 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
danilowoz added a commit that referenced this pull request Jan 24, 2019
* 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
@danilowoz
Copy link
Owner

🎉 This issue has been resolved in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

3 participants