Skip to content

Add TypeScript generics to component types #16935

Description

@yusufkandemir

Needs #16934

People generally recognize it as <script setup lang="ts" generic="T">. But, as Quasar components are not SFCs, nor written in TypeScript, introducing generics is different. We have to start manually authoring TS files, and then add generics on top, which requires #16934.

Adding this feature would allow components like QSelect, QTable, etc. to have type-safety, autocomplete, etc. in their certain props and slots. Here is an example:

<template>
  <q-select
    :options="options"
    :option-value="option => option.id"
    option-label="name"
  />
  <!-- ^^^ `name` doesn't have auto-complete, `option` is seen as any -->
  <!-- With the addition of generics, both props will be aware of the type of `options` -->
</template>

<script setup lang="ts">
const options = [
  { id: 1, name: 'test' }
];
</script>

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions