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

TS error: When I use position restyleFunctions #267

Open
2 tasks done
VictorPulzz opened this issue Jul 17, 2023 · 5 comments
Open
2 tasks done

TS error: When I use position restyleFunctions #267

VictorPulzz opened this issue Jul 17, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@VictorPulzz
Copy link

Current behavior

Hello, I got this error:
image

My code:

export type BaseIconProps = LayoutProps<Theme> & SpacingProps<Theme> & PositionProps<Theme>;
const restyleFunctions = composeRestyleFunctions<Theme, BaseIconProps>([spacing, layout, position]);

Expected behavior

No error:)

Platform:

  • iOS
  • Android

Environment

"react": "18.2.0",
"react-native": "0.71.9",
"@shopify/restyle": "^2.4.2",
"typescript": "~4.8.4"

@VictorPulzz VictorPulzz added the bug Something isn't working label Jul 17, 2023
@VictorPulzz
Copy link
Author

VictorPulzz commented Jul 17, 2023

Okay I miss zIndices section... -_-

@VictorPulzz
Copy link
Author

One question, why I need have section zIndices (if I what use position restyleFuction)?

@VictorPulzz VictorPulzz reopened this Jul 17, 2023
@sebellows
Copy link

One question, why I need have section zIndices (if I what use position restyleFuction)?

I was having the same issue with the border restyle function when passing it to composeRestyleFunction. I added dummy entries to my theme for them and the TS errors went away. Some restyle functions will rely on referring to a themeKey, which the position function does. It refers to a themeKey of zIndices, so zIndices needs to be configured in your theme in order to use position in a composed Restyle function. You can look at the table on the Restyle docs in the right column, the rows that don't say "none" need to be defined in your theme if you plan on using the associated restyle function in composeRestyleFunction.

I guess it'd be nice if maybe Restyle came with some defaults for some common properties that could be over-written if the user wants to, ala Tailwind, e.g.:

{
  border: {
    normal: '#00000033',
    white: '#FFFFFF',
    black: '#000000,
  },
  borderRadii: {
    xs: 2,
    sm: 3,
    md: 4,
    lg: 6,
    xl: 8,
  }
}

But they're not too difficult to add.

@saibbyweb
Copy link

This solved the problem for me:

#169 (comment)

@m-konoval
Copy link

m-konoval commented Apr 26, 2024

Hi, when you're creating a new theme these properties are required to be described at list with {} or undefined if you don't want to meet any Typescript errors

export const theme = createTheme({
    ...,
    colors: {},
    spacing: {},
    breakpoints: {},
    zIndices: undefined,
    borderRadii: undefined,
    ...

Yeh, they might look optional in types definitions, but this trick helps me to avoid any errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants