Skip to content

require-default-prop

Reports a prop that is not required, has no default and is not a Boolean (defineProps({ a: String })). With a type (defineProps<{ a?: string }>()) only a component that sets defaults (withDefaults, a props destructure) is checked.

The prop is undefined when the parent leaves it out, and the template or code then fails on it or shows undefined.

To fix, add a default, or mark the prop required.

Reported
<script>
export default {
props: {
a: String,
b: { type: String, default: '' },
c: { required: true, type: Number },
d: Boolean,
e: [String, Number],
f: {},
g: Object,
},
data() {
...
angular:
lint:
rules:
require-default-prop: warn # off, warn (default), error
html:
lint:
rules:
require-default-prop: warn # off, warn (default), error
svelte:
lint:
rules:
require-default-prop: warn # off, warn (default), error
vue:
lint:
rules:
require-default-prop: warn # off, warn (default), error

Enabled by the presets: html/eslint-plugin-vue-recommended.

Suppress one line with sudsy-disable-next-line require-default-prop in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
eslint-plugin-vue require-default-prop partial a type that comes from another file is skipped (the plugin has no type information there either), a component object only at the top level as for no-dupe-keys