Skip to content

Will the Vue 3 (class component) props API improve ? #456

@LifeIsStrange

Description

@LifeIsStrange

The default component generated with vue cli is like this

@Options({
  props: {
    msg: String
  }
})
export default class HelloWorld extends Vue {
  msg!: string;
}

versus the Vue2 version (class components + property-decorators)

export default class HelloWorld extends Vue {
  @Prop() msg!: string;
}

Reasons why the new API is an obvious downgrade:

  1. Boilerplate wise the new version has a fixed cost of 4 new lines + an additional cost of one redundant line per Prop, this is huge especially for something as common.
  2. You literrally write the same lines twice beyond the boilerplate aspect this is really annoying for thinking process of the dev as it is a non-sensical action (or at best an implementation detail that should never have leak)
    2.1) You write the same types twices making no use of TS inference but actually you can write msg: Number which is an error that will not be catched at compile time.
  3. the worst point is that
export default class HelloWorld extends Vue {
  msg!: string;
}

On the line msg!: string; you have zero visual information that tells you that msg is indeed a Props, one must lookup manually on the props object and remember the association (error prone, and take harmfully cognitive load).

Can this be solved before every sane dev jump on the react ship ? 'sorry for the snark I try sincerely to be constructive here.

@ktsn

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions