Skip to content

Commit

Permalink
fix: enforce consistent type import/export (#5298)
Browse files Browse the repository at this point in the history
  • Loading branch information
GerryWilko committed Jan 10, 2024
1 parent ef4c7b0 commit 82f7310
Show file tree
Hide file tree
Showing 239 changed files with 791 additions and 763 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Expand Up @@ -35,6 +35,9 @@ const config = {
// Todo: do we want these?
'@typescript-eslint/no-explicit-any': 'off',

'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/consistent-type-exports': 'error',

'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
'no-only-tests/no-only-tests': 'error',
Expand Down
Expand Up @@ -2,9 +2,10 @@

import { zodResolver } from '@hookform/resolvers/zod';
import { useRef } from 'react';
import { FormProvider, useForm, UseFormProps } from 'react-hook-form';
import type { UseFormProps } from 'react-hook-form';
import { FormProvider, useForm } from 'react-hook-form';
import { useAction } from 'trpc-api';
import { z } from 'zod';
import type { z } from 'zod';
import { rhfAction } from './ReactHookFormExample.action';
import { rhfActionSchema } from './ReactHookFormExample.schema';

Expand Down
Expand Up @@ -6,24 +6,21 @@
'use client';

import { zodResolver } from '@hookform/resolvers/zod';
import {
inferActionResultProps,
UseTRPCActionResult,
} from '@trpc/next/app-dir/client';
import { TRPCActionHandler } from '@trpc/next/app-dir/server';
import { ActionHandlerDef } from '@trpc/next/dist/app-dir/shared';
import type { UseTRPCActionResult } from '@trpc/next/app-dir/client';
import { inferActionResultProps } from '@trpc/next/app-dir/client';
import type { TRPCActionHandler } from '@trpc/next/app-dir/server';
import type { ActionHandlerDef } from '@trpc/next/dist/app-dir/shared';
import { AnyProcedure, Simplify } from '@trpc/server';
import { useAction } from '~/trpc/client';
import { useRef } from 'react';
import type { UseFormProps, UseFormReturn } from 'react-hook-form';
import {
FormProvider,
useForm,
useFormContext,
UseFormProps,
UseFormReturn,
useWatch,
} from 'react-hook-form';
import { z } from 'zod';
import type { z } from 'zod';

export function createForm<TDef extends ActionHandlerDef>(opts: {
action: TRPCActionHandler<TDef>;
Expand Down
@@ -1,4 +1,4 @@
import { ReactNode } from 'react';
import type { ReactNode } from 'react';
import { FormWithUseActionExample } from './FormWithUseActionExample';
import { RawExample } from './RawExample';
import { RawFormExample } from './RawFormExample';
Expand Down
Expand Up @@ -7,7 +7,7 @@ import { nodeHTTPFormDataContentTypeHandler } from '@trpc/server/adapters/node-h
import { nodeHTTPJSONContentTypeHandler } from '@trpc/server/adapters/node-http/content-type/json';
import { roomRouter } from '~/server/routers/room';
import { createContext, router } from '~/server/trpc';
import { NextApiRequest, NextApiResponse } from 'next';
import type { NextApiRequest, NextApiResponse } from 'next';
import * as undici from 'undici';

const appRouter = router({
Expand Down
Expand Up @@ -2,8 +2,9 @@ import { zodResolver } from '@hookform/resolvers/zod';
import { uploadFileSchema } from '~/utils/schemas';
import { trpc } from '~/utils/trpc';
import { useRef, useState } from 'react';
import { FormProvider, useForm, UseFormProps } from 'react-hook-form';
import { z } from 'zod';
import type { UseFormProps } from 'react-hook-form';
import { FormProvider, useForm } from 'react-hook-form';
import type { z } from 'zod';

/**
* zod-form-data wraps zod in an effect where the original type is a `FormData`
Expand Down
2 changes: 1 addition & 1 deletion examples/.experimental/next-formdata/src/server/trpc.ts
Expand Up @@ -8,7 +8,7 @@
* @see https://trpc.io/docs/procedures
*/
import { initTRPC } from '@trpc/server';
import * as trpcNext from '@trpc/server/adapters/next';
import type * as trpcNext from '@trpc/server/adapters/next';
import { ZodError } from 'zod';

/**
Expand Down
4 changes: 2 additions & 2 deletions examples/.experimental/next-formdata/src/utils/trpc.ts
Expand Up @@ -5,8 +5,8 @@ import {
splitLink,
} from '@trpc/client';
import { createTRPCNext } from '@trpc/next';
import { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
import { AppRouter } from '../pages/api/trpc/[trpc]';
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
import type { AppRouter } from '../pages/api/trpc/[trpc]';

function getBaseUrl() {
if (typeof window !== 'undefined') {
Expand Down
@@ -1,4 +1,4 @@
import * as trpcNext from '@trpc/server/adapters/next';
import type * as trpcNext from '@trpc/server/adapters/next';

interface CreateContextOptions {
// session: Session | null
Expand Down
2 changes: 1 addition & 1 deletion examples/.test/big-router-declaration/src/server/trpc.ts
@@ -1,4 +1,4 @@
import { initTRPC } from '@trpc/server';
import { Context } from '~/server/context';
import type { Context } from '~/server/context';

export const t = initTRPC.context<Context>().create();
2 changes: 1 addition & 1 deletion examples/fastify-server/src/server/router/context.ts
@@ -1,4 +1,4 @@
import { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify';
import type { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify';

export interface User {
name: string[] | string;
Expand Down
2 changes: 1 addition & 1 deletion examples/fastify-server/src/server/router/trpc.ts
@@ -1,6 +1,6 @@
import { initTRPC } from '@trpc/server';
import superjson from 'superjson';
import { Context } from './context';
import type { Context } from './context';

const t = initTRPC.context<Context>().create({
transformer: superjson,
Expand Down
2 changes: 1 addition & 1 deletion examples/next-big-router/src/server/context.ts
@@ -1,4 +1,4 @@
import * as trpcNext from '@trpc/server/adapters/next';
import type * as trpcNext from '@trpc/server/adapters/next';

interface CreateContextOptions {
// session: Session | null
Expand Down
2 changes: 1 addition & 1 deletion examples/next-big-router/src/server/trpc.ts
@@ -1,4 +1,4 @@
import { initTRPC } from '@trpc/server';
import { Context } from './context';
import type { Context } from './context';

export const t = initTRPC.context<Context>().create();
2 changes: 1 addition & 1 deletion examples/next-edge-runtime/src/pages/api/trpc/[trpc].ts
Expand Up @@ -4,7 +4,7 @@
*/
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
import { publicProcedure, router } from '~/server/trpc';
import { NextRequest } from 'next/server';
import type { NextRequest } from 'next/server';
import { z } from 'zod';

const appRouter = router({
Expand Down
@@ -1,5 +1,5 @@
import Head from 'next/head';
import { ReactNode } from 'react';
import type { ReactNode } from 'react';

type DefaultLayoutProps = { children: ReactNode };

Expand Down
4 changes: 2 additions & 2 deletions examples/next-prisma-starter/src/pages/index.tsx
@@ -1,6 +1,6 @@
import { trpc } from '../utils/trpc';
import { NextPageWithLayout } from './_app';
import { inferProcedureInput } from '@trpc/server';
import type { NextPageWithLayout } from './_app';
import type { inferProcedureInput } from '@trpc/server';
import Link from 'next/link';
import { Fragment } from 'react';
import type { AppRouter } from '~/server/routers/_app';
Expand Down
5 changes: 3 additions & 2 deletions examples/next-prisma-starter/src/pages/post/[id].tsx
Expand Up @@ -2,8 +2,9 @@ import NextError from 'next/error';
import Link from 'next/link';
import { useRouter } from 'next/router';

import { NextPageWithLayout } from '~/pages/_app';
import { RouterOutput, trpc } from '~/utils/trpc';
import type { NextPageWithLayout } from '~/pages/_app';
import type { RouterOutput } from '~/utils/trpc';
import { trpc } from '~/utils/trpc';

type PostByIdOutput = RouterOutput['post']['byId'];

Expand Down
2 changes: 1 addition & 1 deletion examples/next-prisma-starter/src/server/context.ts
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as trpcNext from '@trpc/server/adapters/next';
import type * as trpcNext from '@trpc/server/adapters/next';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface CreateContextOptions {
Expand Down
5 changes: 3 additions & 2 deletions examples/next-prisma-starter/src/server/routers/post.test.ts
@@ -1,9 +1,10 @@
/**
* Integration test example for the `post` router
*/
import { inferProcedureInput } from '@trpc/server';
import type { inferProcedureInput } from '@trpc/server';
import { createContextInner } from '../context';
import { AppRouter, createCaller } from './_app';
import type { AppRouter } from './_app';
import { createCaller } from './_app';

test('add and get post', async () => {
const ctx = await createContextInner({});
Expand Down
2 changes: 1 addition & 1 deletion examples/next-prisma-starter/src/server/routers/post.ts
Expand Up @@ -3,7 +3,7 @@
* This is an example router, you can delete this file and then update `../pages/api/trpc/[trpc].tsx`
*/
import { router, publicProcedure } from '../trpc';
import { Prisma } from '@prisma/client';
import type { Prisma } from '@prisma/client';
import { TRPCError } from '@trpc/server';
import { z } from 'zod';
import { prisma } from '~/server/prisma';
Expand Down
2 changes: 1 addition & 1 deletion examples/next-prisma-starter/src/server/trpc.ts
Expand Up @@ -10,7 +10,7 @@

import { initTRPC } from '@trpc/server';
import { transformer } from '~/utils/transformer';
import { Context } from './context';
import type { Context } from './context';

const t = initTRPC.context<Context>().create({
/**
Expand Down
4 changes: 2 additions & 2 deletions examples/next-prisma-starter/src/utils/trpc.ts
@@ -1,7 +1,7 @@
import { httpBatchLink, loggerLink } from '@trpc/client';
import { createTRPCNext } from '@trpc/next';
import { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
import { NextPageContext } from 'next';
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
import type { NextPageContext } from 'next';
// ℹ️ Type-only import:
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export
import type { AppRouter } from '~/server/routers/_app';
Expand Down
6 changes: 3 additions & 3 deletions examples/next-prisma-todomvc/src/pages/[filter].tsx
@@ -1,7 +1,7 @@
import { useIsMutating } from '@tanstack/react-query';
import { inferProcedureOutput } from '@trpc/server';
import type { inferProcedureOutput } from '@trpc/server';
import clsx from 'clsx';
import {
import type {
GetStaticPaths,
GetStaticPropsContext,
InferGetStaticPropsType,
Expand All @@ -14,7 +14,7 @@ import 'todomvc-app-css/index.css';
import 'todomvc-common/base.css';
import { useLocale } from '~/utils/use-locale';
import { InfoFooter } from '../components/footer';
import { AppRouter } from '../server/routers/_app';
import type { AppRouter } from '../server/routers/_app';
import { ssgInit } from '../server/ssg-init';
import { trpc } from '../utils/trpc';
import { useClickOutside } from '../utils/use-click-outside';
Expand Down
7 changes: 4 additions & 3 deletions examples/next-prisma-todomvc/src/pages/_app.tsx
@@ -1,7 +1,8 @@
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { appWithTranslation, SSRConfig } from 'next-i18next';
import { AppProps } from 'next/app';
import { ComponentProps } from 'react';
import type { SSRConfig } from 'next-i18next';
import { appWithTranslation } from 'next-i18next';
import type { AppProps } from 'next/app';
import type { ComponentProps } from 'react';
import { trpc } from '../utils/trpc';

const I18nextAdapter = appWithTranslation<
Expand Down
3 changes: 2 additions & 1 deletion examples/next-prisma-todomvc/src/server/ssg-init.ts
Expand Up @@ -4,7 +4,8 @@ import { i18n } from 'next-i18next.config';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import SuperJSON from 'superjson';
import { createInnerTRPCContext } from './context';
import { AppRouter, appRouter } from './routers/_app';
import type { AppRouter } from './routers/_app';
import { appRouter } from './routers/_app';

export async function ssgInit<TParams extends { locale?: string }>(
opts: GetStaticPropsContext<TParams>,
Expand Down
2 changes: 1 addition & 1 deletion examples/next-prisma-todomvc/src/server/trpc.ts
@@ -1,6 +1,6 @@
import { initTRPC } from '@trpc/server';
import superjson from 'superjson';
import { createInnerTRPCContext } from './context';
import type { createInnerTRPCContext } from './context';

const t = initTRPC.context<typeof createInnerTRPCContext>().create({
transformer: superjson,
Expand Down
3 changes: 2 additions & 1 deletion examples/next-prisma-todomvc/src/utils/use-click-outside.tsx
@@ -1,4 +1,5 @@
import { RefObject, useEffect, useRef } from 'react';
import type { RefObject } from 'react';
import { useEffect, useRef } from 'react';

/**
* Hook for checking when the user clicks outside the passed ref
Expand Down
@@ -1,5 +1,5 @@
import NextAuth from 'next-auth';
import { AppProviders } from 'next-auth/providers';
import type { AppProviders } from 'next-auth/providers';
import CredentialsProvider from 'next-auth/providers/credentials';
import GithubProvider from 'next-auth/providers/github';

Expand Down
Expand Up @@ -3,7 +3,8 @@
*/
import * as trpcNext from '@trpc/server/adapters/next';
import { createContext } from 'server/context';
import { AppRouter, appRouter } from 'server/routers/_app';
import type { AppRouter } from 'server/routers/_app';
import { appRouter } from 'server/routers/_app';

export default trpcNext.createNextApiHandler<AppRouter>({
router: appRouter,
Expand Down
8 changes: 4 additions & 4 deletions examples/next-prisma-websockets-starter/src/server/context.ts
@@ -1,8 +1,8 @@
import * as trpcNext from '@trpc/server/adapters/next';
import { NodeHTTPCreateContextFnOptions } from '@trpc/server/adapters/node-http';
import { IncomingMessage } from 'http';
import type * as trpcNext from '@trpc/server/adapters/next';
import type { NodeHTTPCreateContextFnOptions } from '@trpc/server/adapters/node-http';
import type { IncomingMessage } from 'http';
import { getSession } from 'next-auth/react';
import { WebSocket } from 'ws';
import type { WebSocket } from 'ws';

/**
* Creates context for an incoming request
Expand Down
Expand Up @@ -2,7 +2,7 @@
*
* This is an example router, you can delete this file and then update `../pages/api/trpc/[trpc].tsx`
*/
import { Post } from '@prisma/client';
import type { Post } from '@prisma/client';
import { observable } from '@trpc/server/observable';
import { EventEmitter } from 'events';
import { prisma } from '../prisma';
Expand Down
2 changes: 1 addition & 1 deletion examples/next-prisma-websockets-starter/src/server/trpc.ts
Expand Up @@ -8,7 +8,7 @@
* @see https://trpc.io/docs/procedures
*/

import { Context } from './context';
import type { Context } from './context';
import { initTRPC, TRPCError } from '@trpc/server';
import superjson from 'superjson';

Expand Down
2 changes: 1 addition & 1 deletion examples/next-prisma-websockets-starter/src/utils/trpc.ts
Expand Up @@ -3,7 +3,7 @@ import { loggerLink } from '@trpc/client/links/loggerLink';
import { wsLink, createWSClient } from '@trpc/client/links/wsLink';
import { createTRPCNext } from '@trpc/next';
import type { inferProcedureOutput } from '@trpc/server';
import { NextPageContext } from 'next';
import type { NextPageContext } from 'next';
import getConfig from 'next/config';
import type { AppRouter } from 'server/routers/_app';
import superjson from 'superjson';
Expand Down
12 changes: 4 additions & 8 deletions examples/standalone-server/src/server.ts
@@ -1,12 +1,8 @@
import { initTRPC } from '@trpc/server';
import {
CreateHTTPContextOptions,
createHTTPServer,
} from '@trpc/server/adapters/standalone';
import {
applyWSSHandler,
CreateWSSContextFnOptions,
} from '@trpc/server/adapters/ws';
import type { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';
import { createHTTPServer } from '@trpc/server/adapters/standalone';
import type { CreateWSSContextFnOptions } from '@trpc/server/adapters/ws';
import { applyWSSHandler } from '@trpc/server/adapters/ws';
import { observable } from '@trpc/server/observable';
import { WebSocketServer } from 'ws';
import { z } from 'zod';
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/TRPCClientError.ts
@@ -1,11 +1,11 @@
import {
import type {
AnyProcedure,
AnyRouter,
DefaultErrorShape,
inferRouterError,
Maybe,
} from '@trpc/server';
import { TRPCErrorResponse, TRPCErrorShape } from '@trpc/server/rpc';
import type { TRPCErrorResponse, TRPCErrorShape } from '@trpc/server/rpc';
import { getCauseFromUnknown } from '@trpc/server/shared';
import { isObject } from './internals/isObject';

Expand Down
12 changes: 6 additions & 6 deletions packages/client/src/createTRPCClient.ts
Expand Up @@ -4,16 +4,16 @@ import type {
inferProcedureOutput,
inferSubscriptionOutput,
} from '@trpc/server';
import { Unsubscribable } from '@trpc/server/observable';
import { inferTransformedProcedureOutput } from '@trpc/server/shared';
import {
import type { Unsubscribable } from '@trpc/server/observable';
import type { inferTransformedProcedureOutput } from '@trpc/server/shared';
import type {
CreateTRPCClientOptions,
TRPCRequestOptions,
TRPCSubscriptionObserver,
TRPCUntypedClient,
} from './internals/TRPCUntypedClient';
import { TRPCClientRuntime } from './links';
import { TRPCClientError } from './TRPCClientError';
import { TRPCUntypedClient } from './internals/TRPCUntypedClient';
import type { TRPCClientRuntime } from './links';
import type { TRPCClientError } from './TRPCClientError';

/**
* @deprecated
Expand Down

2 comments on commit 82f7310

@vercel
Copy link

@vercel vercel bot commented on 82f7310 Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

og-image – ./www/og-image

og-image-trpc.vercel.app
og-image-git-main-trpc.vercel.app
og-image-three-neon.vercel.app
og-image.trpc.io

@vercel
Copy link

@vercel vercel bot commented on 82f7310 Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-prisma-starter – ./examples/next-prisma-starter

nextjs.trpc.io
next-prisma-starter-trpc.vercel.app
next-prisma-starter-git-main-trpc.vercel.app

Please sign in to comment.