erquhart
erquhart4mo ago

Convex cache `useQuery` breaks type safety

import { useQuery } from 'convex/react'
import { useQuery as useCachedQuery } from 'convex-helpers/react/cache'

const Component = () => {
const data = useQuery(my.func, {})
// TypeScript will error here because `data` may be undefined
console.log(data.prop)

const cachedData = useCachedQuery(my.func, {})
// TypeScript does not complain, but the value still may be undefined
console.log(cachedData.prop)
}
import { useQuery } from 'convex/react'
import { useQuery as useCachedQuery } from 'convex-helpers/react/cache'

const Component = () => {
const data = useQuery(my.func, {})
// TypeScript will error here because `data` may be undefined
console.log(data.prop)

const cachedData = useCachedQuery(my.func, {})
// TypeScript does not complain, but the value still may be undefined
console.log(cachedData.prop)
}
Any chance I'm holding this wrong?
4 Replies
jamwt
jamwt4mo ago
way over my head. @ian might know
ian
ian4mo ago
great callout - that was an oversight - can you try with convex-helpers@0.1.56-alpha.0 ?
erquhart
erquhartOP4mo ago
Just upgraded to 0.1.56, fixed ✅
jamwt
jamwt4mo ago
🎉