OMikkel / tailwind-datepicker-react

A tailwindcss/flowbite datepicker component built as a react component with types
https://omikkel.github.io/tailwind-datepicker-react/
MIT License
160 stars 70 forks source link

Cannot be used with typescript #19

Closed otatar closed 1 year ago

otatar commented 1 year ago

Cannot be used with typescript:

Could not find a declaration file for module 'tailwind-datepicker-react'
mihaisevencode commented 1 year ago

I was just about to post the same issue 👍

mihaisevencode commented 1 year ago

So... I pulled the repo to take a look at it myself, and the reason why there's no declaration file generated is that the build:dts script fails with the following: image Now, I've checked the TypeScript repo and as per this issue, it looks like this type is only available in es2020. I've played around with changing the target to es2020, but that's causing even more issues: image The only easy way of fixing this I've found is just ts-ignoreing that line, which does emit declaration files. @OMikkel What do you reckon we should do in this case?

mihaisevencode commented 1 year ago

@otatar For the time being, you can just create a tailwind-datepicker-react.d.ts file with the following content:

declare module 'tailwind-datepicker-react' {
  import { ReactElement } from 'react';

  interface ITheme {
    background: string;
    todayBtn: string;
    clearBtn: string;
    icons: string;
    text: string;
    disabledText: string;
    input: string;
    inputIcon: string;
    selected: string;
  }

  interface IIcons {
    prev: () => ReactElement;
    next: () => ReactElement;
  }

  export interface IOptions {
    title?: string;
    autoHide?: boolean;
    todayBtn?: boolean;
    todayBtnText?: string;
    clearBtn?: boolean;
    clearBtnText?: string;
    maxDate?: Date;
    minDate?: Date;
    theme?: ITheme;
    icons?: IIcons;
    datepickerClassNames?: string;
    defaultDate?: Date | null;
    language?: string;
    weekDays?: string[];
    disabledDates?: Date[];
    inputNameProp?: string;
    inputIdProp?: string;
    inputPlaceholderProp?: string;
    inputDateFormatProp?: Intl.DateTimeFormatOptions;
  }

  type DatepickerProps = {
    children?: ReactElement | ReactNode;
    options?: IOptions;
    onChange?: (date: Date) => void;
    show: boolean;
    setShow: (show: boolean) => void;
    classNames?: string;
    selectedDateState?: [Date, (date: Date) => void];
  }

  export default function Datepicker(props: DatepickerProps): ReactElement
}
OMikkel commented 1 year ago

So... I pulled the repo to take a look at it myself, and the reason why there's no declaration file generated is that the build:dts script fails with the following:

image

Now, I've checked the TypeScript repo and as per this issue, it looks like this type is only available in es2020. I've played around with changing the target to es2020, but that's causing even more issues:

image

The only easy way of fixing this I've found is just ts-ignoreing that line, which does emit declaration files. @OMikkel What do you reckon we should do in this case?

I will be pushing a new version where the ts error is ignored. It is not really a huge deal ignoring that error since it obviously exists on the class Intl

nadamai commented 1 year ago

The same issue here :/