Incorrect TS definition for useRestyle hook
See original GitHub issueAfter installing the library via yarn install
the typescript definition for useRestyle
looks like this:
import { StyleProp } from 'react-native';
import { BaseTheme, RestyleFunctionContainer, RNStyle } from '../types';
declare const useRestyle: <Theme extends BaseTheme, TRestyleProps extends Record<string, any>, TProps extends TRestyleProps & {
style?: StyleProp<RNStyle>;
}>(restyleFunctions: (RestyleFunctionContainer<TProps, Theme, keyof TProps, keyof Theme | undefined> | RestyleFunctionContainer<TProps, Theme, keyof TProps, keyof Theme | undefined>[])[], props: TProps) => Pick<TProps, Exclude<keyof TProps, keyof TProps>>;
export default useRestyle;
The return type Pick<TProps, Exclude<keyof TProps, keyof TProps>>
seems incorrect as this always results in:
<Pick<TProps, never>>
(which is the equivalent of {}
)
I imagine the intended behaviour is closer to something like:
Pick<TProps, Exclude<keyof TProps, keyof TRestyleProps>>
Apologies if I’m missing anything obvious 🙏
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
restyle/useRestyle.ts at master - GitHub
A type-enforced system for building UI components in React Native with TypeScript. - restyle/useRestyle.ts at master · Shopify/restyle.
Read more >@shopify/restyle - npm
A system for building constraint-based UI components. Latest version: 2.1.0, last published: 8 months ago. Start using @shopify/restyle in ...
Read more >Restyle for React Native (vs Styled System) - Ryosuke
It's a system for creating UI libraries in React Native with a focus on themeability. This means that your design language (or design...
Read more >shopify/restyle - React Native Dev - Morioh
Breakpoints are defined as minimum widths (inclusive) for different ... For more advanced components, you may want to instead use the useRestyle hook:...
Read more >Wrong function definition in typescript - angular - Stack Overflow
If I run this code it works fine. I have included the upload.service.ts in my code and it worked fine, but after being...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sbalay I did upgrade our repo to the latest version recently and forgot to check - indeed you’re right, the issue is resolved 😃 Thanks for pointer!
@bearkfear and @JuanjoFR - I don’t think either of the TS errors you’re experiencing here are related to this issue.
@bearkfear I can’t be 100% sure for you because you’ve not shared the actual error @JuanjoFR your error is related to some issue with the definition of
restyleFunctions
To give you an example to illustrate the issue I raised, take the following code:
☝️ this results in the following error 👇 :
The definition of
props
returned byuseRestyle
is{}
- which may cause issue depending on the component. In this example, thesource
prop is mandatory but missing in the TS definition for the value returned byuseRestyle
.I hope that’s a bit clearer for everyone, sorry if this was confusing at all.