2

I am getting the errors ts(1109) and ts(1005).

 <Form.Group>
        <Form.Label className={errors.email && 'text-danger'}>
          {errors.email ?? 'Email address'}
        </Form.Label>
        <Form.Control
          type="email"
          value={variables.email}
          className={errors.email && 'is-invalid'}
          onChange={(e) =>
            setVariables({ ...variables, email: e.target.value })
          }
        />
</Form.Group>

I am getting the errors for

{errors.email ?? 'Email address'}

can anyone please tell me how can I resolve this error?

Sarun UK
  • 6,210
  • 7
  • 23
  • 48
Tanish Gupta
  • 400
  • 2
  • 8
  • 20
  • 1
    Are you trying to make a ternary operator here ```{errors.email ?? 'Email address'}```? – yudhiesh Nov 12 '20 at 04:49
  • 4
    Nullish Coalescing operator is supported after version 3.7, make sure your typescript version is supporting that. see https://stackoverflow.com/a/58821005/4354624 – Jerryc Nov 12 '20 at 04:53
  • I'm assuming its supposed to a ternary {errors.email ? 'Email address':'false case'} or if ?? is intentional Babel 7.8.0 or CRA 3.3.0 or above – Hemanth B Nov 12 '20 at 04:53
  • @yudhiesh I am trying to write, if there are no errors, then show Email address. – Tanish Gupta Nov 12 '20 at 04:57
  • 1
    @Tanish you can do `errors.email || 'Email address'` which return `'Email address'` if `errors.email` is `falsy`. while `{errors.email ?? 'Email address'}` return `'Email address'` if `errors.email` is `null` or `undefined`. – Jerryc Nov 12 '20 at 05:27

0 Answers0