question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[name]Target || Value. Unresolved variable in some IDE

See original GitHub issue

How to solve the problem of unknown variables in some IDE? Снимок экрана от 2021-10-07 11-25-02 can better declare variables in scope this ?

example

this.orderQuantity
// or
this.target.orderQuantity

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
fracsicommented, Oct 13, 2021

You could try to add JSDoc to the class (works in Jetbrains IDEs):

import { Controller } from '@hotwired/stimulus'
/**
 * @property {boolean} hasExampleTarget
 * @property {HTMLElement} exampleTarget
 * @property {HTMLElement[]} exampleTargets
 */
export default class YourController extends Controller {
  static targets = ['example']
  someMethod () {
    // All the above listed properties are autocompleted
  }
}
2reactions
vytantcommented, Mar 30, 2022

Our team also struggled with this issue and got tired of poor type checking, so we came up with decorators for targets and values. https://github.com/vytant/stimulus-decorators

import { Controller } from '@hotwired/stimulus';
import { Value, TypedController, Target } from '@vytant/stimulus-decorators';

@TypedController
export default class extends Controller {
  @Value urlValue!: string;
  @Value methodValue: string = 'GET';

  @Target outputTarget!: HTMLElement;
  @Target errorTarget!: HTMLElement;

  connect() {
    fetch(this.urlValue, { method: this.methodValue })
      .then(response => response.json())
      .then(result => {
        this.outputTarget.textContent = result;
      })
      .catch(error => {
        this.errorTarget.textContent = error;
      });
  }
}

All you have to do is define the *Target properties and it will add them to the static targets array. For *Value properties, it takes the type from the type annotation and allows you to assign a default value in a more understandable way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

why is e.target.value giving error unresolved variable with on ...
why is e.target.value giving error unresolved variable with on-click and working fine with on-change.
Read more >
Unresolved variable checked – IDEs Support (IntelliJ Platform)
Hi,. I am using this code: document.getElementById('member').addEventListener('change', (event) => { if (event.target.checked) {
Read more >
AssignMessage policy | Apigee X - Google Cloud
Determines whether processing stops when an unresolved variable is encountered. Each of these child elements is described in the sections that follow. Examples....
Read more >
SoMachine - Programming Guide - 02/2018 - Home
Chapter 18 Network Variables List (NVL) Editor . ... A reset function is available for restoring the default values at any time.
Read more >
IBM Rational Rhapsody User Guide
Operations permitted for fixed-point variables. ... Locating Rational Rhapsody elements in an IDE . ... Target name, Target label, and Tag value.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found