What am I doing wrong?
You're expecting the if (isQuery(item.value)) check to narrow item, but that's not something that happens.
The only situation where item could be narrowed by checking item.value is if item were typed as a discriminated union and value was a discriminant property. That's not the case in your code.