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

chore: convert to typescript #93

Merged
merged 4 commits into from
Nov 5, 2019
Merged

Conversation

sskiswani
Copy link

@sskiswani sskiswani commented Sep 17, 2019

I haven't been able to spend enough time on setting this up with the documentation site and examples, but from what I've been using it for -- this seems to have everything working fairly smoothly.

I opted to using tsdx for doing the builds, although it's fairly opinionated so it might be necessary to directly use rollup if necessary.

Let me know what you think!

EDIT: I just noticed the other PR has more robust generic types, you can close this PR if the other seems more promising

@sskiswani
Copy link
Author

I just noticed that I messed up the npm scripts 😦. I can fix that...

@nihgwu
Copy link
Contributor

nihgwu commented Sep 18, 2019

Thanks for your contribution, don't worry about the documentation site, I'll learn from those two PRs, thanks again

Copy link
Contributor

@nihgwu nihgwu left a comment

Choose a reason for hiding this comment

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

just have a very rough review, can we clean up the todos to continue the work, and do you mind me to change something if necessary?

* Decorator component that automatically adjusts the width and height of a single child
*/
const AutoResizer = ({ className, width, height, children, onResize }) => {
const AutoResizer: React.SFC<AutoResizerProps> = ({ className, width, height, children, onResize }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

React.FC

Comment on lines 5 to 8
/**
* Decorator component that automatically adjusts the width and height of a single child
*/
const AutoResizer = ({ className, width, height, children, onResize }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

why removed the doc here?

const disableWidth = typeof width === 'number';
const disableHeight = typeof height === 'number';

if (disableWidth && disableHeight) {
return (
<div className={className} style={{ width, height, position: 'relative' }}>
{children({ width, height })}
{children({ width: width!, height: height! })}
Copy link
Contributor

Choose a reason for hiding this comment

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

we can't use short hand here?

Copy link
Author

Choose a reason for hiding this comment

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

its because of enabling strict null checks -- tsc thinks width and height might be null, so you have to override it. it works as expected if you put the null checks in the if statement.

if (typeof width === 'number' && typeof height === 'number') {
  return (
    <div className={className} style={{ width, height, position: 'relative' }}>
      {children({ width, height })}
    </div>
  );
}


interface BaseTableState {
scrollbarSize: number;
hoveredRowKey: null;
Copy link
Contributor

Choose a reason for hiding this comment

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

rowKey could be only string | number, I think we could define one and use it in other places, like type RowKey = string | number;

onColumnResize: noop,
};

// TODO: convert to interface
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, please do it

@@ -21,8 +43,8 @@ const AutoResizer = ({ className, width, height, children, onResize }) => {
<AutoSizer className={className} disableWidth={disableWidth} disableHeight={disableHeight} onResize={onResize}>
{size =>
children({
width: disableWidth ? width : size.width,
height: disableHeight ? height : size.height,
width: disableWidth ? width! : size.width,
Copy link
Contributor

Choose a reason for hiding this comment

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

noob question, what is ! for?

Copy link
Author

Choose a reason for hiding this comment

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

it removes null and undefined from the type without having to actually check (new TS docs have a good example about it and strict null check quirks)

@@ -177,8 +480,8 @@ class BaseTable extends React.PureComponent {
*
* @param {object} offset
*/
scrollToPosition(offset) {
this._scroll = offset;
scrollToPosition(offset: { scrollLeft?: number; scrollTop: any }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Offset?


type ClassNameFunc<T = any> = ((args: T) => string) | string;

export const Alignment = {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use enum here?

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, in the next version, I'm going to remove those consts in flavor of a | b | c

Copy link
Author

Choose a reason for hiding this comment

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

👍 for a | b | c

babel doesnt have good support enums. also IMO you get better type checking and intellisense this way.

/**
* Custom style for the column cell, including the header cells
*/
style: PropTypes.object,
Copy link
Contributor

Choose a reason for hiding this comment

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

React.CSSProperties?

Copy link
Author

Choose a reason for hiding this comment

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

the propTypes stuff is a little weird about stuff that isnt propTypes... tbh, havent removed them yet because I use them to keep track of the jsdoc comments when updating the typings.

@sskiswani
Copy link
Author

just have a very rough review, can we clean up the todos to continue the work, and do you mind me to change something if necessary?

Feel free to make any changes -- I'll go through the review comments later today.

@nihgwu
Copy link
Contributor

nihgwu commented Nov 4, 2019

@sskiswani I'm going to merge this PR to move forward, we can take care of the trivials later

@paul-mcgrath
Copy link

Quite interested in using this library, especially if this PR is going to be merged. Do you think that will be today/this week, @nihgwu?

@nihgwu nihgwu changed the title Conversion to typescript (via tsdx) chore: convert to typescript Nov 5, 2019
@nihgwu nihgwu merged commit a1ee1cd into Autodesk:master Nov 5, 2019
@nihgwu
Copy link
Contributor

nihgwu commented Nov 5, 2019

@paul-mcgrath merged, but this is for v2, won't be released in short term

@paul-mcgrath
Copy link

Ah, I missed that detail. Thank you.

@sskiswani
Copy link
Author

@sskiswani I'm going to merge this PR to move forward, we can take care of the trivials later

Cool, let me know ihow I can help!

Also heads up, there's a code base that was giving me issues because allowSyntheticDefaultImports wasn't enabled. I haven't been able to recreate it outside of that project, though.

@nihgwu nihgwu mentioned this pull request Jul 10, 2020
18 tasks
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.

3 participants