question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When a QTable `columns` prop has the `align` set to `'left'` or `'right'` or `'center'` it throws a TypeScript error

See original GitHub issue

What happened?

When a QTable columns prop has the align set to 'left' or 'right' or 'center' it throws this TypeScript error:

Type '({ name: string; label: string; field: string; required: boolean; align: string; sortable: boolean; format?: undefined; } | { name: string; label: string; field: string; sortable: boolean; required?: undefined; align?: undefined; format?: undefined; } | { ...; })[]' is not assignable to type '{ name: string; label: string; field: string | ((row: any) => any); required?: boolean | undefined; align?: "left" | "right" | "center" | undefined; sortable?: boolean | undefined; sort?: ((a: any, b: any, rowA: any, rowB: any) => number) | undefined; ... 5 more ...; headerClasses?: string | undefined; }[]'.
  Type '{ name: string; label: string; field: string; required: boolean; align: string; sortable: boolean; format?: undefined; } | { name: string; label: string; field: string; sortable: boolean; required?: undefined; align?: undefined; format?: undefined; } | { ...; }' is not assignable to type '{ name: string; label: string; field: string | ((row: any) => any); required?: boolean | undefined; align?: "left" | "right" | "center" | undefined; sortable?: boolean | undefined; sort?: ((a: any, b: any, rowA: any, rowB: any) => number) | undefined; ... 5 more ...; headerClasses?: string | undefined; }'.ts(2322)
[index.d.ts(10354, 3): ]()The expected type comes from property 'columns' which is declared here on type 'IntrinsicAttributes & VNodeProps & AllowedComponentProps & ComponentCustomProps & QTableProps'

The align property of QTableProps.columns is typed as align?: "left" | "right" | "center" | undefined; which looks correct. So I have no idea why this is happening.

What did you expect to happen?

No TypeScript error should be showing.

Reproduction URL

n/a

How to reproduce?

  1. Create a new Quasar app using the Quasar CLI. Settings: TypeScript, Sass with SCSS Syntax, EsLint, Composition API, Prettier, NPM.
  2. Create a QTable <q-table title="Tickets" row-key="id" :rows="rows" :columns="columns"></q-table>
  3. Set the align property on the columns prop like so:
const columns = [
  {
    name: 'calories',
    label: 'Calories',
    field: 'calories',
    align: 'center',
  },
];

Now there will be a TypeScript error on :columns.

Flavour

Quasar CLI with Webpack (@quasar/cli | @quasar/app-webpack)

Areas

TypeScript Support

Platforms/Browsers

Chrome

Quasar info output

Operating System - Darwin(21.4.0) - darwin/x64
NodeJs - 14.17.6

Global packages
  NPM - 8.5.4
  yarn - 1.22.11
  @quasar/cli - 1.3.2
  @quasar/icongenie - 2.4.2
  cordova - Not installed

Important local packages
  quasar - 2.6.1 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
  @quasar/app-webpack - 3.4.3 -- Quasar Framework App CLI with Webpack
  @quasar/extras - 1.13.3 -- Quasar Framework fonts, icons and animations
  eslint-plugin-quasar - Not installed
  vue - 3.2.31 -- The progressive JavaScript framework for building modern web UI.
  vue-router - 4.0.13
  pinia - 2.0.11 -- Intuitive, type safe and flexible Store for Vue
  vuex - Not installed
  electron - Not installed
  electron-packager - Not installed
  electron-builder - Not installed
  @babel/core - 7.17.5 -- Babel compiler core.
  webpack - 5.70.0 -- Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.
  webpack-dev-server - 4.7.4 -- Serves a webpack app. Updates the browser on changes.
  workbox-webpack-plugin - Not installed
  register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
  typescript - 4.5.5 -- TypeScript is a language for application scale JavaScript development
  @capacitor/core - Not installed
  @capacitor/cli - Not installed
  @capacitor/android - Not installed
  @capacitor/ios - Not installed

Quasar App Extensions
  *None installed*

Networking
  Host - MacBook-Pro.local
  en0 - 192.168.20.11

Relevant log output

No response

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
BenJackGillcommented, Apr 3, 2022

Hi thanks for the help.

Unfortunatley this did not work for me, it was showing the same error as before:

import { QTableColumn } from 'quasar'

const columns: QTableColumn[] = [
  {
    name: 'calories',
    label: 'Calories',
    field: 'calories',
    align: 'center',
  },
];

But this other solution did work, which was found in the comment you linked:

import { QTableProps } from 'quasar';

const columns: QTableProps['columns'] = [
  {
    name: 'calories',
    label: 'Calories',
    field: 'calories',
    align: 'center',
  },
];
2reactions
taaicommented, May 19, 2022

Hi thanks for the help.

Unfortunatley this did not work for me, it was showing the same error as before:

import { QTableColumn } from 'quasar'

const columns: QTableColumn[] = [
  {
    name: 'calories',
    label: 'Calories',
    field: 'calories',
    align: 'center',
  },
];

But this other solution did work, which was found in the comment you linked:

import { QTableProps } from 'quasar';

const columns: QTableProps['columns'] = [
  {
    name: 'calories',
    label: 'Calories',
    field: 'calories',
    align: 'center',
  },
];

@BenJackGill Thank you! I spent hours to figure this out and finally I came here and saw your solution. I was about to create a new issue, but wanted to check if someone else has created it (to avoid issue duplicates)… Please, include this solution in documentation! 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inovua React Data Grid - can't set textAlign column property ...
type TextAlign = "end" | "left" | "center" | "right" | "start" | undefined;. And then in my columns, I just set the...
Read more >
Word.Interfaces.TableCollectionLoadOptions interface - Office Add ...
For EACH ITEM in the collection: Gets or sets the alignment of the table against the page column. The value can be 'Left',...
Read more >
<tr>: The Table Row element - HTML - MDN Web Docs - Mozilla
The HTML element defines a row of cells in a table. ... use the CSS text-align property to establish left , center ,...
Read more >
Safari Technology Preview Release Notes - Apple Developer
If you already have Safari Technology Preview installed, you can update in the Software Update pane of System Preferences on macOS Monterey, or...
Read more >
Documentation - Everyday Types - TypeScript
JavaScript has three very commonly used primitives: string , number , and boolean . Each has a corresponding type in TypeScript. As you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found