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

Property 'lens' does not exist on type 'ReadOnlyAtom<State>' #85

Open
sbahir opened this issue Aug 22, 2022 · 1 comment
Open

Property 'lens' does not exist on type 'ReadOnlyAtom<State>' #85

sbahir opened this issue Aug 22, 2022 · 1 comment

Comments

@sbahir
Copy link

sbahir commented Aug 22, 2022

I found this codesandbox that was shared by a Grammarly in an engineering post

In line 89 and 90, there is a Typescript compilation error

  const alerts = props.state.lens("alerts");
  const highlights = props.state.lens("highlights");

Property 'lens' does not exist on type 'ReadOnlyAtom<State>'

The code still works but I was intrigued by that knowing that method lens doesn't seem to appear in ReadOnlyAtom as reference here

Can someone explain what I could be missing here?

Should the object be Atom instead of ReadOnlyAtom?

@Nick-bond
Copy link

Should the object be Atom instead of ReadOnlyAtom?

definitely, lens is defined in Atom which extends ReadOnlyAtom so the correct to use

const App = (props: { state: Atom<State> }) => {
  const alerts = props.state.lens("alerts");
  const highlights = props.state.lens("highlights");

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

No branches or pull requests

2 participants