Subscribe on changes!

Make Props required by default

avatar
May 16th 2022

What problem does this feature solve?

The short syntax for typed props is not usable, because these properties are not required by default. So the long syntax should always be used, with the required properties to specify it and the optional properties to set their default value.

I think the code would gain in reliability and readability, if the props were required by default, and the "required" property was removed from the definition and it was the presence of the "default" property, even "null" or "undefined", that made the prop optional.

What does the proposed API look like?

    ...

    propA: Number, // Required number
    propB: [String, Number], // Required number or string
    // Required string -> Deprecated
    propC: {
      type: String,
      required: true //  Useless
    },
    // Number with a default value
    propD: {
      type: Number,
      default: 100 // Make prop optional
    },

   ...
avatar
May 17th 2022

This is going to be a huge breaking change - while I understand why you may want it, it's impractical to change.