props columns at q-table showing error when using typescript #13687
-
when I use quasar typescript and use q-table, there is an error underlined at columns props which have value from columns variable I return from setup(using composition api) like this : the error says: Type '{ name: string; align: string; label: string; field: string; sortable: boolean; }[]' is not assignable to type '{ name: string; label: string; field: string | ((row: any) => any); required?: boolean | undefined; align?: "center" | "left" | "right" | undefined; sortable?: boolean | undefined; sort?: ((a: any, b: any, rowA: any, rowB: any) => number) | undefined; ... 5 more ...; headerClasses?: string | undefined; }[]'. the columns variable returned from setup: I think the element of columns array is match with the type of QTableProps.columns with the required and optional property, but it still give the error like in image preview |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
see the pinned messages in our discord server https://discord.com/channels/415874313728688138/807654245640962059/949981798811729980 |
Beta Was this translation helpful? Give feedback.
-
I created a discord account, gave discord my phone number, installed the app, joined the quasar discord just to get this ;)
|
Beta Was this translation helpful? Give feedback.
-
You can use the <template>
<q-table :rows="users" :columns="columns" />
</template>
<script lang="ts" setup>
import { QTableColumn } from 'quasar';
import { ref } from 'vue';
interface User {
id: number;
name: string;
address: {
city: string;
country: string;
};
}
// You will get auto-complete on properties like `align`('left', 'right', etc.), `field`('id', 'name' and 'address' because of User), etc.
const columns: QTableColumn<User>[] = [
{ name: 'name', align: 'left', label: 'Name', field: 'name' },
{
name: 'city',
align: 'left',
label: 'City',
// row is type of User, we get IntelliSense, etc.
field: (row) => row.address.city,
},
];
const users = ref<User[]>([/* ... */]);
</script> |
Beta Was this translation helpful? Give feedback.
You can use the
QTableColumn
type for this.