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

Incorrect definite assertion for Query #3

Open
Honga1 opened this issue Aug 26, 2021 · 0 comments
Open

Incorrect definite assertion for Query #3

Honga1 opened this issue Aug 26, 2021 · 0 comments

Comments

@Honga1
Copy link
Contributor

Honga1 commented Aug 26, 2021

fluff

Hi :D. I'm exercising the library pretty well at the moment. Well done on it. So far I've only ran into type issues with things like twice extending the Facet class, which wouldn't then carry props into the react component.

Line causing type error

const component = entity.get(t)!;

How I found this

Regarding the line above:
If I have a query

// Note 'hasAny'
const query = useQuery((entity) => entity.hasAny(FacetA, FacetB))

Then follow up with a loop:

query.loop([FacetA, FacetB], (entity, [facetA, facetB]) => {
  assert(facetA !== undefined)
  assert(facetB !== undefined)
}

Would likely throw if I only added one of the two facets FacetA FacetB. Even though they are definitely asserted on your get(t)! part.

Indeed I can reproduce this here:
https://codesandbox.io/s/zealous-nobel-q5id3?file=/src/App.tsx

Suggested fixes

One of:

  • Remove the ! on the get statement
  • Make query.loop filter for components given in first parameter
  • Make returned tuple | undefined
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

1 participant