1

Dear Stackoverflow Community,

I am working on my first Vue-Project with TypeScript. Now I have a Two-Columns-Layout and I try to change only the left side component with one click on a button. But I receive an error code with my following method "changeComponent":

  methods: {
    changeComponent(payload) {
      this.componentName = payload.componentName;
    }
  }

Error: Parameter 'payload' implicitly has an 'any' type.

I am new with TypeScript and would be very grateful for all your inputs. Thank you!

1 Answer 1

1

Typescript doesn't know about the type of payload object. You have to define the types of your Object like this:

interface ObjectChange {
  componentName: string;
  //or
  componentName: number;
  ...
}

const Object = <objectChange[]>require('../data');

Hopefully this helps you out!

Sign up to request clarification or add additional context in comments.

1 Comment

Hi there, thank you for your answer! I am working the first time with vue and have no knowledge of typescript or javascript. I chose now to change my project to a javascript project because there are more tutorials and answers on vue-projects with javascript! But thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.