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

Extension not recognizing props attributes inside setup method #2849

Open
4 tasks done
olegario96 opened this issue Apr 8, 2021 · 5 comments
Open
4 tasks done

Extension not recognizing props attributes inside setup method #2849

olegario96 opened this issue Apr 8, 2021 · 5 comments
Labels

Comments

@olegario96
Copy link

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ
  • I have tried restarting VS Code or running Vetur: Restart VLS

Info

  • Platform: Arch Linux (Kernel 5.11.11)
  • Vetur version: 0.33.1``
  • VS Code version: 1.54.3

Problem

I´m trying to use storybook along with vue and typescript. All linter, builds and tests are working fine, but when opening Button.vue file on my IDE it says: Property 'primary' does not exist on type 'Readonly<{ [x: number]: string; }

error

Component:

<template>
  <button type="button" :class="classes" @click="onClick" :style="style">{{ label }}</button>
</template>

<script lang="ts">
import './button.css';
import { reactive, computed, SetupContext, defineComponent } from 'vue';

export default defineComponent({
  name: 'my-button',

  props: {
    label: {
      type: String,
      required: true,
    },
    primary: {
      type: Boolean,
      default: false,
    },
    size: {
      type: String,
      validator: function (value: string): boolean {
        return ['small', 'medium', 'large'].indexOf(value) !== -1;
      },
    },
    backgroundColor: {
      type: String,
    },
  },

  emits: ['click'],

  setup(props, { emit }: SetupContext) {
    props = reactive(props);
    return {
      classes: computed(() => ({
        'storybook-button': true,
        'storybook-button--primary': props.primary,
        'storybook-button--secondary': !props.primary,
        [`storybook-button--${props.size || 'medium'}`]: true,
      })),
      style: computed(() => ({
        backgroundColor: props.backgroundColor,
      })),
      onClick() {
        emit('click');
      },
    };
  },
});
</script>

Reproducible Case

I was following this tutorial

You can find the source right here in Gitlab.

@yoyo930021
Copy link
Member

@olegario96
Copy link
Author

Hey @yoyo930021 I´ve changed my props to use the following setup:

export default defineComponent({
  name: 'my-button',

  props: {
    label: {
      type: String as PropType<String>,
      required: true,
    },
    primary: {
      type: Boolean as PropType<Boolean>,
      default: false,
    },
    size: {
      type: String as PropType<String>,
      validator: function (value: string): boolean {
        return ['small', 'medium', 'large'].indexOf(value) !== -1;
      },
    },
    backgroundColor: {
      type: String as PropType<String>,
    },
  }
}

But I´m still seeing the same issue.

@yoyo930021
Copy link
Member

Hey @yoyo930021 I´ve changed my props to use the following setup:

export default defineComponent({
  name: 'my-button',

  props: {
    label: {
      type: String as PropType<String>,
      required: true,
    },
    primary: {
      type: Boolean as PropType<Boolean>,
      default: false,
    },
    size: {
      type: String as PropType<String>,
      validator: function (value: string): boolean {
        return ['small', 'medium', 'large'].indexOf(value) !== -1;
      },
    },
    backgroundColor: {
      type: String as PropType<String>,
    },
  }
}

But I´m still seeing the same issue.

The warning say using arrow function or (this: void)

@olegario96
Copy link
Author

@yoyo930021 would mind to add more details? Not sure if I get it right.

@yoyo930021
Copy link
Member

yoyo930021 commented Apr 13, 2021

@yoyo930021 would mind to add more details? Not sure if I get it right.

{
  validator: (value: string) => {
    return ['small', 'medium', 'large'].indexOf(value) !== -1;
  },
}

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

No branches or pull requests

2 participants