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

datas prop type errors when passing values that aren't strings #372

Open
tgrgds opened this issue Sep 25, 2023 · 0 comments
Open

datas prop type errors when passing values that aren't strings #372

tgrgds opened this issue Sep 25, 2023 · 0 comments

Comments

@tgrgds
Copy link

tgrgds commented Sep 25, 2023

Hiya!

In TypeScript, the CsvDownload component compiles and runs as intended when passing in an object such as the following:

type Thing = {
  id: number;
  name: string;
  birthday: Date;
};

const things: Thing[] = [
  {
    id: 12,
    name: "Bob",
    birthday: new Date(2000, 5, 14),
  },
  {
    id: 69420,
    name: "Tim",
    birthday: new Date(1998, 8, 23),
  },
];

However, I get the following type error in my IDE:

No overload matches this call.
  Overload 1 of 2, '(props: ICsvDownloadProps | Readonly<ICsvDownloadProps>): CsvDownload', gave the following error.
    Type 'Thing[]' is not assignable to type 'Datas | (() => Datas) | (() => Promise<Datas>) | Promise<Datas>'.
      Type 'Thing[]' is not assignable to type 'Datas'.
        Type 'Thing' is not assignable to type 'string[] | { [key: string]: string | null | undefined; }'.
          Type 'Thing' is not assignable to type '{ [key: string]: string | null | undefined; }'.
            Property 'id' is incompatible with index signature.
              Type 'number' is not assignable to type 'string'.
  Overload 2 of 2, '(props: ICsvDownloadProps, context: any): CsvDownload', gave the following error.
    Type 'Thing[]' is not assignable to type 'Datas | (() => Datas) | (() => Promise<Datas>) | Promise<Datas>'.ts(2769)

Because datas is expecting string | null | undefined, whereas it should allow anything that can be converted to a string (i.e. string | number | boolean | symbol | object | null | undefined).

Unless I'm missing something silly, I think it should be changed in this line to suit:

export type Datas = (string[] | { [key: string]: string | null | undefined })[]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant