Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSNonNullExpression for non-nullable expressions with array parentheses #115

Closed
steve-py96 opened this issue Feb 17, 2022 · 6 comments
Closed

Comments

@steve-py96
Copy link

CLI warning: The prop value with an expression type of TSNonNullExpression could not be resolved. Please file issue to get this fixed immediately.

Was tracking some of the expressions til I found the cause which looks like this:

<div data-test={someNullishObject![0]} />
@ljharb
Copy link
Member

ljharb commented Feb 17, 2022

What version of jsx-ast-utils are you using? v3.2.0 added support for TSNonNullExpression.

See #82, #108, #71.

@steve-py96
Copy link
Author

Saw those issues too... which is why I was first doubting the error and assumed that I messed up configuring sth. xd

About versions and origins:

❯ npm ls jsx-ast-utils
######################
├─┬ eslint-plugin-jsx-a11y@6.5.1
│ └── jsx-ast-utils@3.2.1
└─┬ eslint-plugin-react@7.28.0
  └── jsx-ast-utils@3.2.1 deduped

@ljharb
Copy link
Member

ljharb commented Feb 17, 2022

hmm, very strange. any idea what code it's warning on?

@steve-py96
Copy link
Author

I have some structure like this (cropping out the contextual most irrelevant)

const Component = () => {
  const [{ data, error }, loading, dispatch] = useStore(asyncSelector, shallow)

  useEffect(() => {
    dispatch({
      loading: 'loading',
    })

    loadData().then(([res_error, res_data]) =>
      dispatch((old) => ({
        loading: 'done',
        local: merge(old.local, {
          error: res_error,
          data: res_data,
        }),
      }))
    )
  }, [])

  if (loading !== 'done') return <Loading />
  if (error !== null) return <Error />

  return (
    <>
      <Link className={styles.link} href={data![0].url} target="_blank">
        text
      </Link>

      ...
    </>
  )
} 

The data![0].url in the href-prop is the issue here, commenting it out/replacing it with a hardcoded string hides the warning.

@ljharb ljharb closed this as completed in f9dffd3 Feb 17, 2022
@steve-py96
Copy link
Author

Woah that's hella weird, I was building a repro and first I was gonna slap myself cause it didn't throw me the warning, but apparently it only throws on interactive HTMLElements (just a guess after testing <button> and <a> yet), therefore this might be caused somewhere else... (was at least my guess before you just fixed this, you're sanic xd)

Thx for fixing ❤️ , I'll leave the repro link here anyway tho, else RIP the effort! :D
https://stackblitz.com/edit/vitejs-vite-cd1axh?file=src%2FApp.tsx&terminal=lint

@ljharb
Copy link
Member

ljharb commented Feb 17, 2022

Luckily i was able to repro it just from that one line :-) we weren't handling bracketed member expressions, specifically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants