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.

The prop 'hasError' generates a TS error, types that are generated based on the docs are incorrect

See original GitHub issue

First of all I deeply apologize for my bad English. I wanted to use the internal validation from quasar and my code is below this text also what I’ve learned is from the docs here : https://quasar.dev/vue-components/input#example--form-validation But The prop ‘hasError’ (that is used for internal validation on inputRef and it gives ‘true’ if the inputs has error) generates a TS error that says Property 'hasError' does not exist on type QInput and I guess there is a problem with the types that are generated based on the docs.

As you can see in the simple code below, I have to use a // @ts-expect-error because the code inuputRef.value?.hasError generates an error and it also gives me what I wanted for validations at the same time. the TS error says : Property 'hasError' does not exist on type QInput but the code is correct and the property ‘hasError’ does exist on type QInput and it’s just the TS types that are generated based on the docs and they are incorrect I guess.

Thanks in advance 🙏

My example code that shows the problem but first remove the // @ts-expect-error from it :

<template>
  <q-page class="flex flex-center" padding>
    <form @submit.prevent.stop="onSubmit">
      <q-card class="full-width" style="max-width: 350px">
        <q-card-section class="bg-primary text-white">
          <div class="text-h6">login</div>
          <div class="text-subtitle2">
           subtext
          </div>
        </q-card-section>

        <q-separator />

        <q-card-actions vertical>
          <q-input
            ref="usernameRef"
            v-model="username"
            standout="bg-teal text-white"
            label="username"
            class="q-my-md"
            hint="this is username"
            lazy-rules
            :rules="usernameRules"
          >
            <template #prepend>
              <q-icon name="fingerprint" />
            </template>
          </q-input>

          <q-input
            ref="passwordRef"
            v-model="password"
            standout="bg-teal text-white"
            label="password"
            class="q-mb-md"
            hint="this is password"
            :type="isPwd ? 'password' : 'text'"
            lazy-rules
            :rules="passwordRules"
          >
            <template #prepend>
              <q-icon name="password" />
            </template>
            <template #append>
              <q-icon
                :name="isPwd ? 'visibility_off' : 'visibility'"
                class="cursor-pointer"
                @click="isPwd = !isPwd"
              />
            </template>
          </q-input>

          <q-btn
            color="secondary"
            icon="login"
            label="login"
            class="q-mb-sm"
            @click="onSubmit"
          />
        </q-card-actions>
      </q-card>
    </form>
  </q-page>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';
import { useQuasar, QInput } from 'quasar';

export default defineComponent({
  name: 'Login',
  setup() {
    const $q = useQuasar();

    const username = ref<string>('');
    const usernameRef = ref<QInput | null>(null);

    const usernameRules = [
      (value: string) =>
        (value !== null && value !== '') ||
        'username cant be null',
    ];

    const password = ref<string>('');
    const passwordRef = ref<QInput | null>(null);

    const passwordRules = [
      (value: string) =>
        (value !== null && value !== '') || 'password cant be null',
    ];

    const isPwd = ref<boolean>(true);

    function onSubmit(): void {
      usernameRef.value?.validate();
      passwordRef.value?.validate();

      // @ts-expect-error     I have to temporary use a (ts-expect-error). Using the prop 'hasError' generates a ts error but it's correct and the docs are incorrect in this point it seems, and there is a problem with the types that are generated based on the docs I guess.
      if (usernameRef.value?.hasError || passwordRef.value?.hasError) {
        $q.notify({
          icon: 'warning',
          color: 'negative',
          message: 'please fix the errors first the press it again',
        });
      } else {
        $q.notify({
          icon: 'done',
          color: 'positive',
          message: 'succeed',
        });
      }
    }

    return {
      username,
      usernameRef,
      usernameRules,
      password,
      passwordRef,
      passwordRules,
      isPwd,
      onSubmit,
    };
  },
});
</script>

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
rstoenescucommented, Jan 7, 2022

hasError is still needed @yusufkandemir

3reactions
yusufkandemircommented, Nov 30, 2021

Thanks for the kind comment, I appreciate it. I totally understand you and agree that this is confusing.

Generally, if something is confusing like this, it might end up being a private thing accidentally used somewhere, or just got overlooked with less to no documentation at all. hasError example is 3 years old, so it might be both. So, that’s why I said we have to evaluate it first. Then, if we consider hasError is something really needed, and we have other dynamic properties for other components as well, we will update the documentation to make them clearer, and they will also be in the API card, just like props, methods, events, etc.

So, I didn’t close the issue because we will evaluate this, and you don’t have to close it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

trouble unit testing reactive form fields in angular
Answering your question. The name.errors['minLength'] returns undefined, Does minLength need to be handled asynchronously? You can just check the form for a ...
Read more >
How To Use Custom Form Validation in Angular - DigitalOcean
Learn how to create a custom validator in Angular for both template-driven and ... If the errors property is empty then the form...
Read more >
Validating form input - Angular
Every time the value of a form control changes, Angular runs validation and generates either a list of validation errors that results in...
Read more >
@prop | typegoose
index​. Accepts Type: boolean. Create an Index for this Property. Should act like the @index class decorator, but without options ...
Read more >
React error handling with react-error-boundary - LogRocket Blog
According to the React documentation, error boundaries do not handle ... constructor(props) { super(props); this.state = { hasError: false }; ...
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