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

Added definitions. #152

Merged
merged 3 commits into from
Sep 10, 2018
Merged

Added definitions. #152

merged 3 commits into from
Sep 10, 2018

Conversation

slig
Copy link
Contributor

@slig slig commented Aug 30, 2018

Using the definitions from #130 by @xaviergonz, I created the react-sizeme.d.ts file and updated the package.json to use them.

Tested locally and it seems to work fine. Would appreciate someone more familiar with TypeScript bless this PR before merging it.

Thanks!

@codecov
Copy link

codecov bot commented Aug 30, 2018

Codecov Report

Merging #152 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #152   +/-   ##
======================================
  Coverage    89.1%   89.1%           
======================================
  Files           4       4           
  Lines         101     101           
  Branches       25      25           
======================================
  Hits           90      90           
  Misses          9       9           
  Partials        2       2

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 0171c46...470731a. Read the comment docs.

noPlaceholder?: boolean;
}

export class SizeMe extends React.Component<SizeMeOptions> {
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should revise this typing to take into account it's render props based API.

I am not familiar with Typescript but found the following possibly helpful article:

https://medium.com/@jrwebdev/react-render-props-in-typescript-b561b00bc67c

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I'll read the article.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe from reading the article that this typing was missing on the SizeMeOptions interface:

children(props: SizeMeProps): JSX.Element;

Now TS complains if we pass anything but a function as a children of the <SizeMe> component, and we get the typings of SizeMeProps on that function as well. (Before on my code I had to manually specify {size} was SizeMeProps like this <SizeMe>{({size}: SizeMeProps) => ... </SizeMe>.

Also, I believe SizeMeProps interface doesn't have to be exported anymore.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, nice one, sounds good. Did you commit/push your latest? Not seeing these changes. 😀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great! I'll commit that change now that you agreed with it.

@ctrlplusb
Copy link
Owner

Thanks for picking this up @slig! Much appreciated.

At first glance it looks great to myself. I think we just need to revise the render props API as commented.

@Igmat
Copy link

Igmat commented Sep 7, 2018

Great work. Will it land any time soon?

@@ -0,0 +1,27 @@
declare module 'react-sizeme' {
Copy link

Choose a reason for hiding this comment

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

Actually, you don't need this, since your package.json includes types property.
I doubt that this will affect end-users somehow, but declare module syntax skipped in both DefinetlyTyped typings and generated by TypeScript compiler.
declare module used only for augmenting host by plugin (e.g. some packages for express do use declare module 'express' for best developers experience) or for typing untyped package from your actual code, when there are no typings for it neither in package nor @types/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing, I'll remove that. I went to see some typings generated by the TS compiler and it emits export declare class Foo instead of just export class Foo. Should I add the declare as well? Thanks!

Copy link

Choose a reason for hiding this comment

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

I don't think so, I don't know why actually TS adds declare to declarations, but it doesn't seem to affect compilation.
But this affects readability of definitions (at least in VS Code), because breaks colorizing(I guess something is wrong with grammar when there are too many reserved words in one statement).

Also, I've just realized, that you don't have react import and you should.
I suggest to use import { Component, ComponentType } from 'react', so typings will work with both esModuleInterop set true and to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect. Thank you very much. Pushed it now.

@ctrlplusb
Copy link
Owner

Raaaaad! Nice one @slig!

@ctrlplusb ctrlplusb merged commit 103dafb into ctrlplusb:master Sep 10, 2018
@slig
Copy link
Contributor Author

slig commented Sep 10, 2018

Great! Thank you very much!

@slig
Copy link
Contributor Author

slig commented Sep 13, 2018

I forgot to add the react-sizeme.d.ts to the files inside the package.json. I'm not sure how you want them added react-sizeme.d.ts or *.d.ts, and if you want me to create this PR or if you can change commit this from your end.

Thanks and sorry!

@mwickett
Copy link

Any chance you can run a release and publish so that these type definitions are available for use? Thanks for adding them!

@feimosi
Copy link

feimosi commented Feb 27, 2019

These typings make default props being ignored in TS > 3.0. Anyone else also experiencing this issue?

@ctrlplusb
Copy link
Owner

@feimosi could you please open an issue with a minimal reproduction?

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.

5 participants