useQueries & queryOptions typing issue
Anyone else running into issue with code similar to:
I am getting: The type QueryKey is readonly and cannot be assigned to the mutable type
When I only use the result of getOptions1 (single item in an array) or remove
queryOptions it does work, not sure what I am doing wrong.5 Replies
correct-apricotOP•14mo ago
@TkDodo 🔮 I started using
queryOptions after seing it being mentioned at https://ui.dev/c/query/avoiding-loading-states, have you ever seen this issue before?fair-rose•14mo ago
I'll take a look today 👀
fair-rose•14mo ago
const queries will get widened to an array, and your services don't return the same type, so it screams.
you need to make your queries a tuple with as const or inline the variable into useQueries. Here is the version with as const:
https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbwLACg5wI4FcCmUCeA8mDMBAHYDOANKulpTgMoNg5U4CKuUwOlqAL5wAZlAgg4AcgACMAIZUFAYwDWAeig55ymAFpsefFNSoY+NnACy+AJLkYeETpxwAvIlEQIALjiUYXnIAczhBUxRlCgC4YJwYYlJogEZ3OAAKOkwefAARePlgABtKPxt7RyhnZRxaNGz+JPI-AKDguoBKdwA+RCytGCwocgaCRLIqdOR69EMCAGkcfD8AbSlKCCGa5KlqUbyC4poGgImAXTr0WZyAMWaMrrdegAVxEGBGADotDaKANxw6QARK1gCEgR1LlcBgQ-M4SrUsugtCJ4soABaEcgAdTBABMIAB3G4QZQMOHyBFQwQdADcQnpKAiUSUsXi42iACY0pl6nMDgojmU7A4nC4oYZThQWoEwe1UI9etNkfEhiN+RzJsqrvzFss4GsNlscJzdvt8oKSntJU0Lkj9nc-OlFXBXhIPjhvvwIP9AclOQBmSH2mH6+GMKEq1EwDFY3HkAnE0nk0SUiNZGmMwSM1AsmJzPiUNIrLJxBIkCaUZK8q6eETePxA9E4IpFCBAsKRuBAm0TIFQ4P1MuayicmtXBBeXzdgBG8igHcEXaBiggMGbUG4jT7WUHZzg8iLeZgzOi8B+WCKMCLHgYzFY7EYW94-CmWQL-CEHQiF6vlBWAAMZyoOo6i1nAAB6AD8qC-teKzJMBKCgeB0FAATS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
fair-rose•14mo ago
remove
as const from line 42 to get the errorcorrect-apricotOP•14mo ago
Thanks, this works! 🙂