Skip to content
Advertisement

Vue 3 Typescript define unknown array of object

I’m using vue 3 with quasar and I would to make a wrapper for q-table but how can I define rows without using any[].

It works like this but then whenever I use this component I’ll have to convert my object to unknown. Is there any better way? Or I should just turn off “no-explicit-any” and use any[]?

JavaScript

Advertisement

Answer

QTable.rows expects an array of objects, containing string keys and string/number values.

So rows should be typed as:

JavaScript

Side notes:

  • Specifying undefined as a default value is effectively the same as not specifying a default at all. You can remove the withDefaults() in your example.

  • The computed props that just return the original props have no useful effect. You could remove these computed props, and just use props.rows and props.columns directly.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement