vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.76k stars 6.33k forks source link

vue3 typescript props error TS2339: Property 'xxx' does not exist on type 'unknown'. #6886

Open ChobitsSP opened 2 years ago

ChobitsSP commented 2 years ago

Version

4.5.15

Reproduction link

github.com

Environment info

  System:
    OS: Windows 10 10.0.19042
    CPU: (16) x64 Intel(R) Core(TM) i9-9900 CPU @ 3.10GHz
  Binaries:
    Node: 14.18.2 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 6.14.11 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 96.0.4664.110
    Edge: Spartan (44.19041.1266.0), Chromium (96.0.1054.62)
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

npm i npm run serve

then the CheckBoxList component show TS2339 error in the terminal

What is expected?

https://v3.vuejs.org/guide/typescript-support.html#annotating-props

What is actually happening?

ERROR in src/components/CheckBoxList.vue:40:56 TS2339: Property 'length' does not exist on type 'unknown'. 38 | setup(props, { emit }) { 39 | const state = ref([]);

40 | const checkAll = computed(() => props.modelValue.length > 0 && props.modelValue.length === props.options.length); | ^^^^^^ 41 | const isIndeterminate = computed(() => props.modelValue.length > 0 && !checkAll.value); 42 | 43 | const onUpdate = (value: any[]) => {

ERROR in src/components/CheckBoxList.vue:40:87 TS2339: Property 'length' does not exist on type 'unknown'. 38 | setup(props, { emit }) { 39 | const state = ref([]);

40 | const checkAll = computed(() => props.modelValue.length > 0 && props.modelValue.length === props.options.length); | ^^^^^^ 41 | const isIndeterminate = computed(() => props.modelValue.length > 0 && !checkAll.value); 42 | 43 | const onUpdate = (value: any[]) => {

ERROR in src/components/CheckBoxList.vue:40:112 TS2339: Property 'length' does not exist on type 'unknown'. 38 | setup(props, { emit }) { 39 | const state = ref([]);

40 | const checkAll = computed(() => props.modelValue.length > 0 && props.modelValue.length === props.options.length); | ^^^^^^ 41 | const isIndeterminate = computed(() => props.modelValue.length > 0 && !checkAll.value); 42 | 43 | const onUpdate = (value: any[]) => {

ERROR in src/components/CheckBoxList.vue:41:63 TS2339: Property 'length' does not exist on type 'unknown'. 39 | const state = ref([]); 40 | const checkAll = computed(() => props.modelValue.length > 0 && props.modelValue.length === props.options.length);

41 | const isIndeterminate = computed(() => props.modelValue.length > 0 && !checkAll.value); | ^^^^^^ 42 | 43 | const onUpdate = (value: any[]) => { 44 | state.value = value;

ERROR in src/components/CheckBoxList.vue:48:87 TS2339: Property 'map' does not exist on type 'unknown'. 46 | }; 47 |

48 | const handleCheckAllChange = () => onUpdate(checkAll.value ? [] : props.options.map(t => t.value)); | ^^^ 49 | 50 | return { 51 | state,

ChobitsSP commented 2 years ago

if i use config.plugins.delete('fork-ts-checker') then the project npm run serve / build both working well