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

Custom component props are not being resolved during build time #246

Open
eliobricenov opened this issue Mar 27, 2024 · 0 comments
Open
Labels
Priority: 4 - Low Type: Tech Non functional requirement or refactor

Comments

@eliobricenov
Copy link
Collaborator

eliobricenov commented Mar 27, 2024

it seems there's an issue with the UI lib build types

when we declare the props of a component and they either:

  • extend a prop from another custom component
  • use the interface of a different custom component

they are not resolved by typescript and when we install the package they are any

for example, this one doesn't work:

import cn from 'classnames'

import {
  ContainerInteractive,
  ContainerInteractiveProps
} from '@/components/ContainerInteractive'
import Select, { SelectProps } from '@/components/Select'
import TextInput, { TextInputProps } from '@/components/TextInput'

import styles from './RewardFormCard.module.scss'

export interface RewardFormCardProps extends ContainerInteractiveProps {
  networkInputProps?: SelectProps
  tokenContractAddressInputProps?: TextInputProps
  tokenTypeInputProps?: SelectProps
}

function RewardFormCard({ classNames, ...props }: RewardFormCardProps) {
  return (
    <ContainerInteractive
      classNames={{
        ...classNames,
        title: cn(styles.title, classNames?.title),
        root: cn(styles.root, classNames?.root)
      }}
      {...props}
    >
      <Select {...props.networkInputProps} />
      <TextInput {...props.tokenContractAddressInputProps} />
      <Select {...props.tokenTypeInputProps} />
      {props.children}
    </ContainerInteractive>
  )
}

export default RewardFormCard

it is resolved to:

interface RewardFormCardProps {
  networkInputProps?: any
  tokenContractAddressInputProps?: any
  tokenTypeInputProps?: any
}

If we redefined the props inside of the custom component instead of using the existing ones, they are set correctly during build time, so it is definitely about Typescript not being able to resolve the imports from other files

import React, { ComponentPropsWithoutRef, ReactElement } from 'react'

import {
  SelectProps as MantineSelectProps,
  TextInputProps as MantineTextInputProps
} from '@mantine/core'
import cn from 'classnames'

import { ContainerInteractive } from '../ContainerInteractive'
import Select from '../Select'
import TextInput from '../TextInput'
import styles from './RewardFormCard.module.scss'

interface SelectProps extends Omit<MantineSelectProps, 'size'> {
  size?: 'small' | 'medium' | 'large'
}

interface TextInputProps extends MantineTextInputProps {
  size?: 'small' | 'medium' | 'large'
  classNames?: {
    root?: string
    input?: string
    wrapper?: string
    label?: string
    section?: string
    error?: string
    charCounter?: string
    required?: string
  }
  maxCharacters?: number
}

export interface RewardFormCardProps extends ComponentPropsWithoutRef<'div'> {
  title: string
  tag?: ReactElement
  icon?: ReactElement
  classNames?: {
    root?: string
    header?: string
    titleContainer?: string
    title?: string
  }
  networkInputProps?: SelectProps
  tokenContractAddressInputProps?: TextInputProps
  tokenTypeInputProps?: SelectProps
}

function RewardFormCard({ classNames, ...props }: RewardFormCardProps) {
  return (
    <ContainerInteractive
      classNames={{
        ...classNames,
        title: cn(styles.title, classNames?.title),
        root: cn(styles.root, classNames?.root)
      }}
      {...props}
    >
      <Select {...props.networkInputProps} />
      <TextInput {...props.tokenContractAddressInputProps} />
      <Select {...props.tokenTypeInputProps} />
      {props.children}
    </ContainerInteractive>
  )
}

export default RewardFormCard
@eliobricenov eliobricenov added Priority: 4 - Low Type: Tech Non functional requirement or refactor labels Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: 4 - Low Type: Tech Non functional requirement or refactor
Projects
None yet
Development

No branches or pull requests

1 participant