gluestack

gluestack Logogluestack

When updating most components ( V2 -> latest V2 ) they break because of new typings

andbutsothen posted this in #support
Open in Discord
Avatar
andbutsothenOP
Since gluestack ui V2 is in beta and I see a lot of fixes / changes, I want to keep these comonents in sync. However, a lot of the updates have changed typings and look to require a new ref. For instance on Box it went from...

 import React from 'react';

import { boxStyle } from './styles';

const Box = React.forwardRef(({ className, ...props }: any, ref) => {
  return <div ref={ref} className={boxStyle({ class: className })} {...props} />;
});

Box.displayName = 'Box';

export { Box };


...to....

 import React from 'react';
import { boxStyle } from './styles';
import type { ViewProps } from 'react-native';
import type { VariantProps } from '@gluestack-ui/nativewind-utils';

type Similar<T, U> = {
  [K in keyof T & keyof U]: T[K] extends U[K]
    ? U[K] extends T[K]
      ? T[K]
      : never
    : never;
};

type IBoxProps = Similar<ViewProps, React.ComponentPropsWithoutRef<'div'>> &
  VariantProps<typeof boxStyle>;

const Box = React.forwardRef<HTMLDivElement, IBoxProps>(
  ({ className, ...props }, ref) => {
    return (
      <div ref={ref} className={boxStyle({ class: className })} {...props} />
    );
  }
);

Box.displayName = 'Box';
export { Box };


And this now breaks my use of this component. Here is the TS error...

Type '{ children: Element[]; className: string; }' is missing the following properties from type 'Similar<ViewProps, Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">>': style, id, tabIndex, onTouchStart, and 29 more.

Type
is missing the following properties from type :



What can be done to make sure upgrading V2 works as beta components evolve ?
Image

17 Replies

Avatar
viraj1098
@sravankumar101 Can you help ?
Avatar
sravankumar101
hey @andbutsothen
Does your project contains this file nativewind-env.d.ts with content /// <reference types="nativewind/types" /> ?
Avatar
andbutsothenOP
@sravankumar101 yes it does
It only gives me issues with I try to install an upated V2 component.
Avatar
sravankumar101
That might be due to the types are not getting attached for newly installed components. You could restart your ts server in your editor and check whether the issue resolves or please feel free to raise a github issue on this.
Avatar
andbutsothenOP
Thanks @sravankumar101 . I will followup on GH if restarting doesn't work.
Avatar
tread2779
I'm having the same issue. Please let me know if you make a gh issue or figure out a workaround @andbutsothen @sravankumar101
Avatar
sravankumar101
hey @tread2779 @andbutsothen Could you remove the components that are currently causing this type issue and re-install them once again.We've updated them such that it resolves this type issue.
Avatar
tread2779
Perfect! I see the changes. Thank you
Image
Image
Avatar
sravankumar101
You are most welcome @tread2779
Avatar
andbutsothenOP
@sravankumar101 thank you! How would I update any code for the ~/project/components/ui/gluestack-ui-provider ?

If you improve or update the provider files, how would I access this ? ... there is no npx command to install/update this that I see.
Avatar
sravankumar101
hey @andbutsothen
There will not be any major improvements in the provider file, we may directly improve in the package.Else if we are making any update on provider files we will provide some guide in the documentation to update the file or will create a command .
Avatar
andbutsothenOP
@sravankumar101 I appreciate the reply. Is there a GH link you can send to look at the last Provider or other components for V2 ? I could not find them last time I looked.
Avatar
sravankumar101
hey @andbutsothen I didn't get you,Could you please rephrase it . All the components are listed on the docs page btw.
Avatar
andbutsothenOP
@sravankumar101 Where in GitHub would I find the very latest versions of each V2 file ?

The directory is a bit confusing for me to navigate and I wasn to look at the latest components ( Provider, Button, ETC ) in GitHub.