ioulian / next-io-ghent-starter

Next.js starter kit for iO Ghent
https://ioulian.github.io/next-io-ghent-starter/
4 stars 0 forks source link

Add styled props helper #8

Closed ioulian closed 1 year ago

ioulian commented 2 years ago

import { ComponentProps } from "react"; import { StyledComponentInnerComponent, StyledComponentInnerOtherProps, AnyStyledComponent, StyledComponentPropsWithRef, } from "styled-components";

export type inferStyledTypes = ComponentProps< StyledComponentInnerComponent

& StyledComponentInnerOtherProps & StyledComponentPropsWithRef;

ioulian commented 2 years ago

Better:

import { ComponentPropsWithRef, JSXElementConstructor } from "react";
import {
  AnyStyledComponent,
  StyledComponentInnerComponent,
  StyledComponentInnerOtherProps,
} from "styled-components";

export type InferStyledComponentProps<T> = T extends AnyStyledComponent
  ? ComponentPropsWithRef<StyledComponentInnerComponent<T>> &
      StyledComponentInnerOtherProps<T>
  : // eslint-disable-next-line no-undef
  T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>
  ? ComponentPropsWithRef<T>
  : never;
ioulian commented 1 year ago

InferStyledComponentProps -> InferComponentProps

timdujardin commented 1 year ago

Fixed in https://github.com/ioulian/next-io-ghent-starter/commit/6ace95548dcd9deab3facd513d415cf1835234dc.