Skip to content

Allow component prop validation of 'Array of type' in javascript #8804

@Andrioden

Description

@Andrioden

What problem does this feature solve?

Reading the documentation, searching the web and the issues list here, it seems prop validator for 'Array Of Type' dont exist.

This feature enables the following things:

  • Vue out-of-box validation array of types
  • Allow PyCharm and other IDE vendors to easily create type hinting based on prop type
  • Allow linters to easily validate vue template according to prop type

I understand the answer might be "you should use TypeScript", but I have a fairly decently typed javascript project, and would like to try to keep it that way while praying js types will be approved in the future.

What does the proposed API look like?

Constrained by the javascript language, and your current design, these are my suggestions

import { ArrayOf, Of } from 'vue'

export default {
  props: {
     suggestionA: {
         type: ArrayOf,
         of: SomeClass
     },
     suggestionB: {
         type: Array,
         of: SomeClass
     },
     suggestionC: {
         type: Array,
         arrayOf: SomeClass
     },
     suggestionD: [Array, Of, SomeClass],
     suggestionE: ArrayOf(SomeClass)
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions