nasheomirro / react-polymorphed

A set of types to help easily create fast polymorphic components.
MIT License
24 stars 3 forks source link

Typescript not picking up undefined/null #4

Closed iivic17 closed 1 year ago

iivic17 commented 1 year ago
export type TypographyProps = {
    variant: keyof TypographyVariants<string>;
    className?: string | undefined;
    count?: number | null;
};

export const defaultComponent = 'span';

export type TypographyPolymorphicProps = PolymorphicComponent<
    typeof defaultComponent,
    PropsWithChildren<TypographyProps>
>;

and in such case

const Typography: TypographyPolymorphicProps = ({
    as: As = defaultComponent,
    variant,
    className,
    children,
    count,
    ...props
}) => {

The component will see className and count only as string/number, even though they are optional parameters and explicitly set to undefined/null

iivic17 commented 1 year ago

Screenshot 2023-04-04 at 12 13 40

nasheomirro commented 1 year ago

Hey @iivic17 , this might be a problem with your typescript config having the strictNullChecks set to false. If your config doesn't have that, then I might need a ts playground that produces said issue cause I can't really reproduce it in other ways.