Skip to content

Add typescript definition file #35

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

Closed
wants to merge 6 commits into from

Conversation

jnpdx
Copy link

@jnpdx jnpdx commented Sep 11, 2019

Summary

This adds an index.d.ts Typescript definition file to the project. The typings are taken either directly from Typescript's inferences of the functions or from React Native's types via @types/react-native

This adds out-of-the-box Typescript support. Note that it does depend on @types/react-native, although I did not add this to peerDependencies since only Typescript users need this and would obviously have it installed already.

Test Plan

What's required for testing (prerequisites)?

Add react-native-hooks to a Typescript enabled React Native project.

What are the steps to reproduce (after prerequisites)?

Typings should be available with all of the same syntax/usage as before.

Compatibility

OS Implemented
iOS
Android

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I mentioned this change in CHANGELOG.md
  • I updated the typed files (TS and Flow)
  • I added a sample use of the API in the example project (example/App.js)

layout: { x: number; y: number; width: number; height: number };
};
}) => void;
};

Choose a reason for hiding this comment

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

The type LayoutRectangle could be imported from react-native and then this could be changed to:

declare function useLayout(): LayoutRectangle & {
  onLayout: (event: {
    nativeEvent: {
      layout: { x: number; y: number; width: number; height: number };
    };
  }) => void;
};

@jnpdx
Copy link
Author

jnpdx commented Sep 12, 2019

Good catch. Updated to use that type both in the nativeEvent as well.

@paldepind
Copy link

@jnpdx That's even better 😄

@paldepind paldepind mentioned this pull request Sep 17, 2019
@marnusw
Copy link

marnusw commented Sep 21, 2019

Since useDeviceOrientation is a concept of this library's own creation and doesn't map directly to RN could we add an exported interface for its return value?

export interface DeviceOrientation {
  portrait?: boolean
  landscape?: boolean
}

declare function useDeviceOrientation(): DeviceOrientation

@jnpdx
Copy link
Author

jnpdx commented Sep 21, 2019

New suggestions from @marnusw implemented

@asurare
Copy link

asurare commented Oct 24, 2019

Why is this PR not merged ?

@pvinis
Copy link
Member

pvinis commented Oct 25, 2019

I'm guessing people are waiting for a move to typescript? We should merge this anyway until this happens. Also I started a PR for a move to typescript and I would appreciate people's help there so we can finish quicker.

#41

@pvinis
Copy link
Member

pvinis commented Mar 16, 2020

Closing this. Now that we moved to TS, this is generated. Thanks everyone for the input and help!

@pvinis pvinis closed this Mar 16, 2020
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