Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prop boolean required type error #8852

Open
liuzw2579 opened this issue Jul 27, 2023 · 4 comments · May be fixed by #12326
Open

prop boolean required type error #8852

liuzw2579 opened this issue Jul 27, 2023 · 4 comments · May be fixed by #12326

Comments

@liuzw2579
Copy link

liuzw2579 commented Jul 27, 2023

@Shyam-Chen
Copy link
Contributor

Shyam-Chen commented Jul 27, 2023

Required:

<script lang="ts" setup>
const props = defineProps<{
  b1: boolean;
  b2: boolean;
  b3: boolean;
  s1: string;
  s2: string;
}>();
</script>

Optional:

<script lang="ts" setup>
const props = defineProps<{
  b1?: boolean;
  b2?: boolean;
  b3?: boolean;
  s1?: string;
  s2?: string;
}>();
</script>

@caohongz
Copy link

PropType一般用于定义复杂变量(例如:数组、对象、函数)的类型定义,布尔类型或字符串类型直接定义即可,PropType会造成prop变量接口定义为可选变量。

@yangliguo7
Copy link
Contributor

yangliguo7 commented Aug 11, 2023

also confuse here

Is the type returned by DefineProps generated by this Readonly<ExtractPropTypes<{ x:Boolean }>> ?

check the mini RP

https://www.typescriptlang.org/play?#code/C4TwDgpgBACgTgezAWQsAFggJgHgCoA0UeAwggHYDOwcArgMbAJxQC8UAhuSAHxtQBtPAF0oEAB7AI5LJUEAoKFAAUygHQaOcAOaUAXJ24BKNny4gTAHyi0ZEAGYBLchCzzRAeg9RH9n3PtbRkcKKAB3RwxOHUoiDgAbeIQI8m0ocgoAWjgIAEdaRxysKEDyYIpKRSgAfigAb3SIMJUjA1IKmgYmOABuFra+nI4sCniQKDBEJlBINrIqTsZmKABfKC8oEiGpKAAxIOAQ8ih4xwBraHoOuiW4KoMXADcIO-kJMGZgKBnoABEOYAcfgAJQgVzguGocGc2iItjOGTC5B48nkP1giDA8yhXWY+H45j4rCq1gaLma6k0MQM5gEwlaxCgADJ6msViT6v1Ge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3ajwGuY4khpO+bbczSX4prFUbU+AX0cFoPreRaeQS39T38bYeCBnjuCsAQ5d4I0TPKBSQcB5TAClkFHAYYbyF1UrQSg0AUogNgE5M48CiBISbjnACQEEE8Fys4agdZigVxSng0sWBc7wJId8BAUA9JgA+HAL4mFfggRKHWYAtAciVCLiXZwZcAIVxgFgnBWd8F0MIQwngVdxYCTgLA+BNcURrBZEgjYKC0EYMkfQbBYYiDfgoH+eRxDSELAoVAKhZjyAWLQgg3KfFWHsM4dw3hAIBFBSqMXUuBipEmKgA4pxRCeCKPLIrVRyt7Rhg0Seb24gPF+02PVD4LhyDAEuowJ0lAHFARgPwTUHBEH+JEccAxSjtYwA0SaJiSTUQbH6uMDA0BxATExOkBAXxG60JqOAgAGiCChoxFRgRoNA2BQEGjiD0LvLgqxImoiAA

why the x prop is optional not required ?

@caohongz
Copy link

also confuse here

Is the type returned by DefineProps generated by this Readonly<ExtractPropTypes<{ x:Boolean }>> ?

check the mini RP

https://www.typescriptlang.org/play?#code/C4TwDgpgBACgTgezAWQsAFggJgHgCoA0UeAwggHYDOwcArgMbAJxQC8UAhuSAHxtQBtPAF0oEAB7AI5LJUEAoKFAAUygHQaOcAOaUAXJ24BKNny4gTAHyi0ZEAGYBLchCzzRAeg9RH9n3PtbRkcKKAB3RwxOHUoiDgAbeIQI8m0ocgoAWjgIAEdaRxysKEDyYIpKRSgAfigAb3SIMJUjA1IKmgYmOABuFra+nI4sCniQKDBEJlBINrIqTsZmKABfKC8oEiGpKAAxIOAQ8ih4xwBraHoOuiW4KoMXADcIO-kJMGZgKBnoABEOYAcfgAJQgVzguGocGc2iItjOGTC5B48nkP1giDA8yhXWY+H45j4rCq1gaLma6k0MQM5gEwlaxCgADJ6msViT6v1GeylNZ4EhUBhsPgUWjwH8HBxaPFgLsOLcQCL+MpJkh9FB-oCTKw+HgoNZyNL4vqbHYnC43GLIBikHhxUr2PysddcXAlXzMdjFt0RXTUc4pHB7PLoE6APJgQ4VfHscxEX78PB8OpVH7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BAUA9JgA+HAL4mFfggRKHWYAtAciVCLiXZwZcAIVxgFgnBWd8F0MIQwngVdxYCTgLA+BNcURrBZEgjYKC0EYMkfQbBYYiDfgoH+eRxDSELAoVAKhZjyAWLQgg3KfFWHsM4dw3hAIBFBSqMXUuBipEmKgA4pxRCeCKPLIrVRyt7Rhg0Seb24gPF+02PVD4LhyDAEuowJ0lAHFARgPwTUHBEH+JEccAxSjtYwA0SaJiSTUQbH6uMDA0BxATExOkBAXxG60JqOAgAGiCChoxFRgRoNA2BQEGjiD0LvLgqxImoiAA

why the x prop is optional not required ?

In my opinion, props in vue3 are defined as optional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants