Skip to content

Conversation

@Dorian30
Copy link
Contributor

@Dorian30 Dorian30 commented Apr 15, 2020

Summary

  • Added tsconfig.js file with all the relevant config needed for TS.
  • Built TS routes to make dynamic import available.
  • Installed required dependencies.
  • Added index.d.ts file to be able to import .png files
  • Typed the entire project using TS. Hooks & HOCs too.
  • Made minor refactor on custom header component, since I cannot longer use it as before due to type checking.
  • Added default values for global context provider. It is required when using TS.
  • Typed both useLazyRequest and useRequest Hooks. Same with withLoader hook.
  • Fixed some issues that came to the surface thanks to TypeScript.
  • Dynamic enums were typed using const assertion from TS as const
  • Static enums were typed using explicit enums from TS.
  • Made reusable interfaces.

Screenshots

iPhone X

iPhoneX

iPhone 8

iPhone 8

iPhone 7

iPhone 7

Pixel 3XL

3XL

Pixel 3

P3

Pixel 2

P2

Trello Card

https://trello.com/c/MwfBmj9p/54-typescript-ii-pr%C3%A1ctica

@Dorian30 Dorian30 requested a review from guidoprinc April 15, 2020 13:26
@Dorian30 Dorian30 changed the title Book TypesSript [WIP] Book TypesSript Apr 15, 2020

interface Props {
onPress: () => void;
backButton: number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think there is an ImageType from react-native. Check it out or leave it like this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I'll look into it 👀


interface Props {
scene: {
descriptor: { options: { title?: string; headerStyle?: { height: number }; hasBackBtn?: boolean } };
Copy link
Collaborator

Choose a reason for hiding this comment

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

when you declare types for styles you can use ViewStyles instead of writing each one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. Didn't know that one!

scene: {
descriptor: { options: { title?: string; headerStyle?: { height: number }; hasBackBtn?: boolean } };
};
navigation: { goBack(): void };
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think there are interfaces from react-navigation, https://reactnavigation.org/docs/4.x/typescript

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'll check the doc

const {
options: { title, headerStyle }
} = scene.descriptor;
const { height } = headerStyle!;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are you doing this? Do you only want the height and nothing else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I just want the height to get the height set in screenOptions. I could just define within the header's styles, but according to the doc (or what I read from it) it is best to set it from screenOptions so both the custom and the default header have the same height

import { APP_OPTIONS, LOGIN_OPTIONS } from './constants';

interface Props {
token: string | null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

token?: string; or you receive null's sometimes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default value for the token, inside the globalState, is null. So I would always get a value: string | null. I thought of setting undefined in the globalState and set token? instead, but as a good practice I don't like to set undefined manually.

const { data: response, loading } = useRequest<Response>(getBook, { id });
const { image, title, author, year, genre } = response?.data || DEFAULT_BOOK;
return (
<BookDetail image={image} title={title} author={author} year={year} genre={genre} isLoading={loading} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

you could directly destruct in here with ...data and declare data as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright! 👍

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