`boolean` prop shouldn't be required when defined with `defineProps`

This issue has been created since 2022-11-18.

Version

2.7.14

Reproduction link

stackblitz.com

Steps to reproduce

Use component having a boolean prop without passing this prop

// HelloWorld.vue
defineProps<{ msg: boolean }>();
// App.vue
<template>
  <HelloWorld />
</template>

What is expected?

No warning in the browser console

What is actually happening?

Missing required prop warning

image

sxzz wrote this answer on 2022-11-18

It's by design. Try defineProps<{ msg?: boolean }>();

jacekkarczmarczyk wrote this answer on 2022-11-19

Then this design is incosistent with design of other types and with object syntax

edison1105 wrote this answer on 2022-11-19

@jacekkarczmarczyk
this is designed since vue2.
If the type of an attribute is boolean and set the default value to undefined. it do esn't make sense. undefined is also a falsely value when we use it. right?

jacekkarczmarczyk wrote this answer on 2022-11-19

Are you suggesting that this is a bug in Chrome that displays undefined as false?
image

Also undefined is falsy, right, but it's not false. In typescript it matters

jacekkarczmarczyk wrote this answer on 2022-11-19

TBH while I agree that the required prop might indeed throw a warning when not provided, the bigger problem is that non-required prop behaves differently with typescript and object syntax:
prop: Boolean (no required: true) - prop type is boolean
prop?: boolean - prop type is boolean | undefined (but still false is being passed when prop is not provided)
So I understand why this issue was closed (why the false value is passes though instead of undefined?), but I've created an issue in Vue 3 repo about this inconsistency and imho bad DX

More Details About Repo
Owner Name vuejs
Repo Name vue
Full Name vuejs/vue
Language TypeScript
Created Date 2013-07-29
Updated Date 2022-12-10
Star Count 201155
Watcher Count 6070
Fork Count 33134
Issue Count 595

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Update MacOS installation guidelines in OpenRefine's manual 0 2022-11-22 2022-11-19
Create new intro video for OpenRefine explaining most used features 0 2022-11-18 2022-11-19
Extract yandex-metrika module 3 2021-01-12 2022-11-25
Lecture 13 - Example function does not do the expected 1 2021-06-08 2022-04-08
Move "hints" to the bottom of the exercise file 2 2021-08-18 2022-10-09
New Tool request: base64 to file 0 2022-02-23 2022-10-07
VOXELFORMAT: IMAP chunk in magicavoxel file is not handled properly 1 2020-12-06 2022-08-02
error with line 7, in <module> 3 2020-02-20 2022-08-25
feat: Create an user role indicator icon for non-manger roles 2 2021-10-15 2021-12-30
What is your setup for those crystal clear gifs? 4 2021-07-03 2022-12-01
关于闭包与作用链关系的讨论 2 2020-08-20 2022-01-15
fix httpc warning at compiletime. 1 2021-04-26 2022-11-27
UseConnectionProvider<> fails 1 2022-11-01 2022-11-20
Quartz.Net failed on server 0 2022-11-04 2022-11-20
support for schemas 4 2021-07-16 2021-12-18
Ambiguous serialized keys 3 2021-06-28 2022-12-06
在Auto.js Pro V8中如何导入Java类? 1 2020-02-07 2022-12-06
Can't evaluate last page in willDrawCell 1 2021-03-01 2022-11-11
Emgu.CV.dll Emgu.CV.UI.dll Emgu.Util.dll 0 2022-10-22 2022-12-09
建议:默认禁用插件的pdf阅读功能 太简陋而且很难找到关闭按钮 0 2022-03-31 2022-12-05
(Bug) cat a binary file cause display exception 0 2022-09-16 2022-10-09
\u000e messy code problem 0 2022-09-13 2022-10-09
Update k8s audit endpoint 6 2020-07-01 2022-12-09
owasp/modsecurity-crs:{nginx/apache} as a standalone webserver 5 2022-02-23 2022-10-18
Update the Meetups and Covid page CDC urls 1 2022-05-22 2022-11-12
КРИТИКАЛ!!! orderbook по инструменту у Вас вообще что показывает??? 5 2021-08-04 2021-12-27
SandpackProvider: `files` prop doesn't work with `template` prop 1 2021-09-23 2022-12-04
Failed set beneficiary request 3 2022-06-17 2022-09-30
[Icon request] TheLounge 0 2022-02-13 2022-10-20
Improve the system for assigning Skybox HDR texture assignments 1 2022-05-25 2022-11-18
upgrade dies midway and renders wallabag unusable if php < 7.4.1 3 2022-07-05 2022-11-13
[prim] Certain assertions do not trigger in vcs 4 2022-08-11 2022-09-19
[Bug]: "Swap from" field only displays 2 characters 0 2022-09-23 2022-12-03
Preferences not saving in elevated privileges 1 2019-01-06 2022-12-09
"Untrusted node" use case is hindered by ability to re-tag without reauthenticating 2 2021-12-16 2022-09-30
Recalculate Tooltip position when content changes 2 2021-04-16 2022-10-22
setStyle()/style property throws "Cannot read properties of undefined (reading 'expression')" for some style.json files 1 2022-02-01 2022-09-25
aws kinesis - add tests for terraform adapters 0 2022-03-27 2022-11-04
TypeError: Invalid PostCSS Plugin found at: plugins[0] 0 2021-03-17 2022-11-25
多组柱形+折线图,使用不同position渲染,tooltip不居中 5 2022-09-21 2022-12-02
Update status of Concept Exercises 1 2021-01-29 2022-11-24
Sql projects table designer description issues 2 2022-06-13 2022-10-06
[BUG]项目管理>>文件管理:这里上传了数据文件和jar包,因为还需要上传jar,但是发现无法上传,提示超过上线。 0 2022-10-12 2022-10-07
Terminal resizing does not take position into account 0 2022-01-17 2022-09-11
Layer violations in Structure101 24 2022-01-17 2022-10-31
To group buttons of extensions in left bar 1 2022-01-17 2022-10-09
bugfix: Oracle MySQL JDBC XXE漏洞(CVE-2021-2471) 0 2022-06-27 2022-11-23
Missing support for `startsWith` for dynamic metric alert rule 3 2021-12-20 2022-11-15
Loading other dependencies mentioned in plugin pom 7 2021-07-06 2022-11-20
Should alerting, actions and task manager telemetry have field(s) to capture when the telemetry job failed? 2 2022-07-07 2022-09-18