Detective Baby Legs
Detective Baby Legs
TTCTheo's Typesafe Cult
Created by Detective Baby Legs on 2/27/2024 in #questions
Avoid UseQuery() Undefined Key Lint Error on Next Build
Here's the error:
Type error: No overload matches this call.
Overload 1 of 2, '(input: { key: string; }, opts: DefinedUseTRPCQueryOptions<"curator.getWorkItemByKey", { key: string; }, WorkItem, WorkItem, TRPCClientErrorLike<BuildProcedure<"query", { _config: RootConfig<{ ctx: { curatorDb: Sql<{}>; }; meta: object; errorShape: { ...; }; transformer: typeof SuperJSON; }>; ... 5 more ...; _output_out: typeof unsetMarker; }, WorkItem>>, WorkItem>): DefinedUseTRPCQueryResult<...>', gave the following error.
Type 'string | string[] | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
Overload 2 of 2, '(input: { key: string; }, opts?: UseTRPCQueryOptions<"curator.getWorkItemByKey", { key: string; }, WorkItem, WorkItem, TRPCClientErrorLike<BuildProcedure<"query", { _config: RootConfig<{ ctx: { curatorDb: Sql<{}>; }; meta: object; errorShape: { ...; }; transformer: typeof SuperJSON; }>; ... 5 more ...; _output_out: typeof unsetMarker; }, WorkItem>>, WorkItem> | undefined): UseTRPCQueryResult<...>', gave the following error.
Type 'string | string[] | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.

13 | const router = useRouter();
14 | const workItem = api.curator.getWorkItemByKey.useQuery(
> 15 | { key: router.query.key },
| ^
16 | { retry: false, enabled: !!router.query.key },
17 | );
18 |
Type error: No overload matches this call.
Overload 1 of 2, '(input: { key: string; }, opts: DefinedUseTRPCQueryOptions<"curator.getWorkItemByKey", { key: string; }, WorkItem, WorkItem, TRPCClientErrorLike<BuildProcedure<"query", { _config: RootConfig<{ ctx: { curatorDb: Sql<{}>; }; meta: object; errorShape: { ...; }; transformer: typeof SuperJSON; }>; ... 5 more ...; _output_out: typeof unsetMarker; }, WorkItem>>, WorkItem>): DefinedUseTRPCQueryResult<...>', gave the following error.
Type 'string | string[] | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
Overload 2 of 2, '(input: { key: string; }, opts?: UseTRPCQueryOptions<"curator.getWorkItemByKey", { key: string; }, WorkItem, WorkItem, TRPCClientErrorLike<BuildProcedure<"query", { _config: RootConfig<{ ctx: { curatorDb: Sql<{}>; }; meta: object; errorShape: { ...; }; transformer: typeof SuperJSON; }>; ... 5 more ...; _output_out: typeof unsetMarker; }, WorkItem>>, WorkItem> | undefined): UseTRPCQueryResult<...>', gave the following error.
Type 'string | string[] | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.

13 | const router = useRouter();
14 | const workItem = api.curator.getWorkItemByKey.useQuery(
> 15 | { key: router.query.key },
| ^
16 | { retry: false, enabled: !!router.query.key },
17 | );
18 |
Its only occuring because typescript doesn't understand useQuery() enabled. I'm not sure a good way to avoid this though. Do I just put a lint error ignore?
2 replies