Dani;
Dani;
TtRPC
Created by Dani; on 10/27/2022 in #❓-help
v10 migration using codemod
So I've been looking at the codemod that helps with transition towards v10 and I haven't been able to get it to work, my setup (simplified):
// the following structure is inside /server/trpc/src
├── context.ts // createContext
├── index.ts // main router entry point, this mainly does .merge calls to subrouters (auth.router.ts)
├── middlewares
│ └── meta-routers.ts // this is where I'm exporting createPrivateRouter
├── utils
│ └── trpc.ts // this is where I'm calling initializing v10 stuff ( exporting mergeRouters, privateProcedure... )
├── routers
│ ├── auth
│ │ ├── auth.router.ts // subrouter that merges every procedure in the subfolder (signin.ts)
│ │ ├── auth.router.test.ts // tests for this specific router ( using .createCaller() calls )
│ │ ├── procedures
│ │ │ └── signin.ts // this exports a single procedure using `export default createPrivateRouter.query('....')`
// the following structure is inside /server/trpc/src
├── context.ts // createContext
├── index.ts // main router entry point, this mainly does .merge calls to subrouters (auth.router.ts)
├── middlewares
│ └── meta-routers.ts // this is where I'm exporting createPrivateRouter
├── utils
│ └── trpc.ts // this is where I'm calling initializing v10 stuff ( exporting mergeRouters, privateProcedure... )
├── routers
│ ├── auth
│ │ ├── auth.router.ts // subrouter that merges every procedure in the subfolder (signin.ts)
│ │ ├── auth.router.test.ts // tests for this specific router ( using .createCaller() calls )
│ │ ├── procedures
│ │ │ └── signin.ts // this exports a single procedure using `export default createPrivateRouter.query('....')`
Running the following command while in /server/trpc/
npx trpc-v10-migrate-codemod \
--router-factory createPrivateRouter \
--base-procedure privateProcedure \
--import privateProcedure:~/src/utils/trpc
npx trpc-v10-migrate-codemod \
--router-factory createPrivateRouter \
--base-procedure privateProcedure \
--import privateProcedure:~/src/utils/trpc
So after running this, every file in the project is printed to the console i.e. migrated ...../server/trpc/src/routers/auth.router.ts, however, the only files that are changed are the test files (the ones using .createCaller()), those are migrated correctly. Not sure what is wrong, maybe I'm overlooking something. Any help is greatly appreciated.
1 replies
TtRPC
Created by Dani; on 10/13/2022 in #❓-help
data becomes never[] when destructuring with a fallback value
Currently it doesn't seem possible to set a fallback value on a destructured data property, for example:
const { data = [] } = trpc.useQuery(['company.listIds']);
// expecting data to be the inferred type { id: string }[] but instead it's never[]


// This somehow works
const query = trpc.useQuery(['company.listIds']);
const { data = [] } = query;
// data is correctly typed as { id: string }[]
const { data = [] } = trpc.useQuery(['company.listIds']);
// expecting data to be the inferred type { id: string }[] but instead it's never[]


// This somehow works
const query = trpc.useQuery(['company.listIds']);
const { data = [] } = query;
// data is correctly typed as { id: string }[]
The "equivalent" with pure react-query:
interface Company {
id: string;
}
const { data = [] } = useQuery<Company[]>(['company.listIds'], someFetchFunction);
// data is correctly typed as Company[]
interface Company {
id: string;
}
const { data = [] } = useQuery<Company[]>(['company.listIds'], someFetchFunction);
// data is correctly typed as Company[]
Does anyone know if there's a way to achieve the same behaviour of react-query in @trpc/react?
18 replies