Skip to content

Property 'value' does not exist on type 'SceneVariableState' when using behaviors.ActWhenVariableChanged #1016

Open
@tredman

Description

@tredman

Hello! I'm trying Grafana Scenes for the first time using a new app bootstrapped by @grafana/create-plugin. I'm working through some examples and running into an error when trying to use the ActWhenVariableChanged behavior, described here. Here's my code, more or less copied directly from the the docs.

  const logWhenVariableChanges = new behaviors.ActWhenVariableChanged({
    variableName: 'serviceName',
    onChange: (variable) => {
      console.log(`serviceName value changed: ${variable.state.value}`);
    },
  });

I get the following typescript error when compiling, but the code otherwise seems to work (I see the console log messages when the variable changes as expected).

ERROR in ./src/pages/APMView/scenes.tsx:44:64
TS2339: Property 'value' does not exist on type 'SceneVariableState'.
    42 |     variableName: 'serviceName',
    43 |     onChange: (variable) => {
  > 44 |       console.log(`serviceName value changed: ${variable.state.value}`);
       |                                                                ^^^^^
    45 |     },
    46 |   });
    47 |

Found 1 error in 1513 ms.

I'm not really a JS/TS developer so I'm pretty far out of my element but it seems like either the TS config is too strict or the value property is just missing from the SceneVariableState definition.

interface SceneVariableState extends SceneObjectState {
    type: VariableType;
    name: string;
    label?: string;
    hide?: VariableHide;
    skipUrlSync?: boolean;
    loading?: boolean;
    error?: any | null;
    description?: string | null;
}

Am I doing something wrong here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions