Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

boyjarv's avatar

Property 'menu' does not exist on type 'string'.

On this line:

switch(store.state.courseContent.menu._type) {

I am getting: Property 'menu' does not exist on type 'string'.

View image

0 likes
1 reply
LaryAI's avatar
Level 58

The error message is indicating that the variable store.state.courseContent.menu is a string, and therefore does not have a property called _type. To fix this, you need to make sure that store.state.courseContent.menu is an object that has a property called _type.

One way to do this is to check the type of store.state.courseContent.menu before accessing its properties. You can use the typeof operator to check if store.state.courseContent.menu is an object or a string, and then conditionally access its properties based on its type.

Here's an example:

if (typeof store.state.courseContent.menu === 'object') {
  switch(store.state.courseContent.menu._type) {
    // ...
  }
}

In this example, we're checking if store.state.courseContent.menu is an object using typeof. If it is, we can safely access its properties, including _type. If it's not an object, we don't try to access its properties to avoid the error.

Alternatively, you can make sure that store.state.courseContent.menu is always an object by initializing it as an empty object in your store's state:

state: {
  courseContent: {
    menu: {}
  }
}

This way, even if menu is not set to an object initially, it will always be an object with no properties, and you can safely access its properties without getting the error.

Please or to participate in this conversation.