roxena
roxena

Reputation: 209

Vue change-component with TypeScript

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!

Upvotes: 1

Views: 423

Answers (1)

B0BBY
B0BBY

Reputation: 1109

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!

Upvotes: 1

Related Questions