Home > Blockchain >  access static values in a Stimulus Typescript controller with the default settings from Symfony
access static values in a Stimulus Typescript controller with the default settings from Symfony

Time:06-16

I'm trying to learn Stimulus with a more or less default install of Symfony6 and Encore, one of the main differences with the default install being that I'm using Typescript. The Stimulus docs say that typed values should be used like so =>

export default class extends Controller {
  static values = { index: Number }

  initialize() {
    console.log(this.indexValue)
    console.log(typeof this.indexValue)
  }

  // …
}

However when using Typescript, I get a TS2339: Property 'indexValue' does not exist on type 'default'. on accessing this.indexValue; I managed to get away with this with a @ts-ignore but I think that sucks. Do you know of any cleaner way to handle this in a webpack Encore Symfony project ? Thanks in advance

  • Related