Skip to content

typecheck fails when trying to call render with a generic component #443

Open
@axel7083

Description

@axel7083

let's have the following (Svelte4) generic component called Table.svelte

<script lang="ts" generics="T extends { selected?: boolean; name?: string }">
export let data: T[];
</script>

Let's have our table.spec.ts

import '@testing-library/jest-dom/vitest';

import { fireEvent, render, screen, within } from '@testing-library/svelte';

// Import our generic component
import { Table } from '/@/lib';

// let's create an Item interface
interface Item {
  id: string;
  name?: string;
}

test('type issue', async () => {
  render<Table<Item>>(Table, {
      kind: 'demo',
      data: [
        {
          id: '1',
          name: 'foo',
        },
        {
          id: '2',
          name: 'foo',
        },
      ],
    });
});

Got the following error

packages/ui/src/lib/table/Table.spec.ts:463:37 - error TS2315: Type 'Comp' is not generic.

463     const { getAllByRole } = render<Table<Item>>(Table, {

Trying something different

-   render<Table<Item>>(Table, {
+  render(Table<Item>, {

Got the following error

packages/ui/src/lib/table/Table.spec.ts:463:37 - error TS2345: Argument of type '{}' is not assignable to parameter of type 'Component<any, any, string> | (new (...args: any[]) => SvelteComponent<any, any, any>)'.        

463     const { getAllByRole } = render(Table<Item>, {
                                        ~~~~~~~~~~~

packages/ui/src/lib/table/Table.spec.ts:463:43 - error TS2635: Type 'LegacyComponentType' has no signatures for which the type argument list is applicable.

463     const { getAllByRole } = render(Table<Item>, {

If am not specifying the I've got the following error in my IDE (not typecheck)

TS2353: Object literal may only specify known properties, and id does not exist in type

Metadata

Metadata

Assignees

No one assigned

    Labels

    missing reproductionIssue needs a reproduction or it may be closed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions