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

Argument of type 'Column<DataType>' is not assignable to parameter of type 'Column<unknown>'. #247

Open
johanrd opened this issue Feb 20, 2024 · 0 comments

Comments

@johanrd
Copy link
Contributor

johanrd commented Feb 20, 2024

Hi. I get a type error on all column modifiers (e.g. resizeHandle) Argument of type 'Column<DataType>' is not assignable to parameter of type 'Column<unknown>'.

Argument of type 'Column<DataType>' is not assignable to parameter of type 'Column<unknown>'.
  The types returned by 'table.args.named.columns()' are incompatible between these types.
    Type 'ColumnConfig<DataType>[]' is not assignable to type 'ColumnConfig<unknown>[]'.
      Type 'ColumnConfig<DataType>' is not assignable to type 'ColumnConfig<unknown>'.
        Types of property 'value' are incompatible.
          Type '((context: CellContext<DataType>) => ContentValue) | undefined' is not assignable to type '((context: CellContext<unknown>) => ContentValue) | undefined'.
            Type '(context: CellContext<DataType>) => ContentValue' is not assignable to type '(context: CellContext<unknown>) => ContentValue'.
              Types of parameters 'context' and 'context' are incompatible.
                Type 'CellContext<unknown>' is not assignable to type 'CellContext<DataType>'.
                  The types returned by 'column.table.args.named.columns()' are incompatible between these types.
                    Type 'ColumnConfig<unknown>[]' is not assignable to type 'ColumnConfig<DataType>[]'.
                      Type 'ColumnConfig<unknown>' is not assignable to type 'ColumnConfig<DataType>'.
                        Types of property 'value' are incompatible.
                          Type '((context: CellContext<unknown>) => ContentValue) | undefined' is not assignable to type '((context: CellContext<DataType>) => ContentValue) | undefined'.
                            Type '(context: CellContext<unknown>) => ContentValue' is not assignable to type '(context: CellContext<DataType>) => ContentValue'.
                              Types of parameters 'context' and 'context' are incompatible.
                                Type 'CellContext<DataType>' is not assignable to type 'CellContext<unknown>'.
                                  Types of property 'row' are incompatible.
                                    Type 'Row<DataType>' is not assignable to type 'Row<unknown>'.
                                      Type 'unknown' is not assignable to type 'DataType'.glint(2345)

It seems like the Column modifiers does not pass on the types of the Column, and instead always assigns the default Column<T = unknown>:

export class Column<T = unknown> {

See example of steps to reproduce with resizeHandle:

import Component from '@glimmer/component'
import { headlessTable }  from 'ember-headless-table'
import { ColumnResizing, resizeHandle } from 'ember-headless-table/plugins/column-resizing'

interface ColumnType {
  name: string;
  key: keyof DataType;
}

interface DataType {
  firstName: string;
  lastName: string;
}

export default class HeadlesseTableExample extends Component {

  get columns() : ColumnType[] {
    return [ {name: 'First Name', key: 'firstName'}, {name: 'Last Name', key: 'lastName'}]
  }

  get rows() : DataType[] {
    return [{firstName: 'John', lastName: 'Doe'}]
  }

  table = headlessTable(this, {
    columns: () => this.columns,
    data: () => this.rows,
    plugins: [ ColumnResizing ],
  });

  <template>
    <div {{this.table.modifiers.container}}>
      <table class='border-b w-full' {{this.table.modifiers.container}}>
        <thead>
          <tr>
            {{#each this.table.columns as |column|}}
              <th {{this.table.modifiers.columnHeader column}}>
                {{!--column errors here--}}
                <button {{resizeHandle column}}> 
                  ↔
                </button>
              </th>
            {{/each}}
          </tr>
        </thead>
      </table>
    </div>
  </template>
}
@johanrd johanrd changed the title Argument of type 'Column<RowInterface>' is not assignable to parameter of type 'Column<unknown>'. Argument of type 'Column<DataType>' is not assignable to parameter of type 'Column<unknown>'. Feb 21, 2024
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