Skip to content

TypeScript example for onSelect #110

Open

Description

@MichalBryxi

Given:

  table = headlessTable<Row>(this, {
    columns: () => this.args.columns, // this.args.columns: ColumnConfig<Row>[]
    data: () => this.args.data, // this.args.data: Row[]
    plugins: [
      RowSelection.with(() => {
        return {
          selection: [],
          onSelect: (data) => { // Parameter 'data' implicitly has an 'any' type.
            ...
          },
          onDeselect: () => {},
        };
      }),
    ],
  });

I would hope that the first data argument of onSelect hook would give me correct type on the first argument (data) and not any. Or what would be the correct TS usage?

I can obviously just do:

onSelect: (data: T) => { ... }

but that feels ... unnecessary?

Activity

  1. NullVoxPopuli commented on Oct 1, 2025

    @NullVoxPopuli
    Contributor

    Yes, that is expected to work, and this not working is a bug. Thanks for reporting!

  2. added theissue type on Oct 1, 2025
  3. johanrd commented on Oct 13, 2025

    @johanrd
    Contributor

    okay, I'm not sure this is an easy fix. Currently in src/plugins/-private/base.ts:106-111, the with method signature is:

    static with<T extends BasePlugin<any>>(
    this: Constructor<T>,
    configFn: () => OptionsFor<SignatureFrom<T>>,
    ): [Constructor<T>, () => OptionsFor<SignatureFrom<T>>] {
    return [this, configFn];
    }

    Not sure, but I don't see how to pass generics through static methods in a way that would automatically infer the DataType from the table context. A possible solution may be to have a factory method pattern like RowSelection.for().with(...), but that does not help much in practice, as you'd still need to pass in the generic yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions