Skip to content

Commit

Permalink
chore(lint): re-enable @typescript-eslint/ban-types (trpc#3464)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT authored and nfabredev committed Dec 23, 2022
1 parent 9535379 commit a02430d
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 22 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-floating-promises": "error",
"no-only-tests/no-only-tests": "error",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-empty-interface": "off",
"unicorn/filename-case": [
"error",
Expand Down
6 changes: 3 additions & 3 deletions packages/react-query/src/createTRPCReact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export type DecorateProcedure<
>,
];
}
: {})
: {}) &
: object)
: object) &
(TFlags extends 'ExperimentalSuspense'
? {
useSuspenseQuery: <
Expand All @@ -126,7 +126,7 @@ export type DecorateProcedure<
UseTRPCQuerySuccessResult<TData, TRPCClientErrorLike<TProcedure>>,
];
}
: {})
: object)
: TProcedure extends AnyMutationProcedure
? {
useMutation: <TContext = unknown>(
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/adapters/node-http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type NodeHTTPCreateContextOption<
TRouter extends AnyRouter,
TRequest,
TResponse,
> = {} extends inferRouterContext<TRouter>
> = object extends inferRouterContext<TRouter>
? {
/**
* @link https://trpc.io/docs/context
Expand Down
8 changes: 5 additions & 3 deletions packages/server/src/core/initTRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ type PartialRootConfigTypes = Partial<RootConfigTypes>;

type CreateRootConfigTypesFromPartial<TTypes extends PartialRootConfigTypes> =
CreateRootConfigTypes<{
ctx: TTypes['ctx'] extends RootConfigTypes['ctx'] ? TTypes['ctx'] : {};
meta: TTypes['meta'] extends RootConfigTypes['meta'] ? TTypes['meta'] : {};
ctx: TTypes['ctx'] extends RootConfigTypes['ctx'] ? TTypes['ctx'] : object;
meta: TTypes['meta'] extends RootConfigTypes['meta']
? TTypes['meta']
: object;
errorShape: TTypes['errorShape'];
transformer: DataTransformerOptions;
}>;
Expand All @@ -42,7 +44,7 @@ type CreateRootConfigTypesFromPartial<TTypes extends PartialRootConfigTypes> =
* - Doesn't need to be a class but it doesn't really hurt either
*/

class TRPCBuilder<TParams extends PartialRootConfigTypes = {}> {
class TRPCBuilder<TParams extends PartialRootConfigTypes = object> {
context<TNewContext extends RootConfigTypes['ctx']>() {
return new TRPCBuilder<FlatOverwrite<TParams, { ctx: TNewContext }>>();
}
Expand Down
3 changes: 3 additions & 0 deletions packages/server/src/core/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ export interface RouterDef<
* @deprecated
*/
TOld extends DeprecatedProcedureRouterRecord = {
// eslint-disable-next-line @typescript-eslint/ban-types
queries: {};
// eslint-disable-next-line @typescript-eslint/ban-types
mutations: {};
// eslint-disable-next-line @typescript-eslint/ban-types
subscriptions: {};
},
> {
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/deprecated/interop.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-types */
import { ProcedureParams, ProcedureType } from '..';
import { AnyRootConfig, RootConfig } from '../core/internals/config';
import { getParseFnOrPassThrough } from '../core/internals/getParseFn';
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/deprecated/router.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types */

/* eslint-disable @typescript-eslint/no-explicit-any */
import { TRPCError } from '../error/TRPCError';
import { defaultFormatter } from '../error/formatter';
Expand Down
6 changes: 5 additions & 1 deletion packages/server/src/shared/internal/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ type JsonPrimitive =
| string
| number
| boolean
// eslint-disable-next-line @typescript-eslint/ban-types
| String
// eslint-disable-next-line @typescript-eslint/ban-types
| Number
// eslint-disable-next-line @typescript-eslint/ban-types
| Boolean
| null;
// eslint-disable-next-line @typescript-eslint/ban-types
type NonJsonPrimitive = undefined | Function | symbol;

/*
Expand All @@ -24,7 +28,7 @@ type IsAny<T> = 0 extends 1 & T ? true : false;
export type Serialize<T> =
IsAny<T> extends true ? any :
T extends JsonPrimitive ? T :
T extends Map<any,any> | Set<any> ? {} :
T extends Map<any,any> | Set<any> ? object :
T extends NonJsonPrimitive ? never :
T extends { toJSON(): infer U } ? U :
T extends [] ? [] :
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type ThenArg<TType> = TType extends PromiseLike<infer U>
*/
export type Simplify<TType> = TType extends any[] | Date
? TType
: { [K in keyof TType]: TType[K] } & {};
: { [K in keyof TType]: TType[K] };
/**
* @public
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/server/___testHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export async function waitMs(ms: number) {
await new Promise<void>((resolve) => setTimeout(resolve, ms));
}

type Constructor<T extends {} = {}> = new (...args: any[]) => T;
type Constructor<T extends object = object> = new (...args: any[]) => T;

export async function waitError<TError extends Error = Error>(
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/server/children.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ test('w/o children', async () => {
foo,
});

expectTypeOf(router._def.procedures.foo).toMatchTypeOf(foo);
expectTypeOf(router._def.procedures.foo).toEqualTypeOf(foo);
});
8 changes: 4 additions & 4 deletions packages/tests/server/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('smoke test', async () => {
});

test('mix query and mutation', async () => {
type Context = {};
type Context = object;
const t = initTRPC.context<Context>().create();

const router = t.router({
Expand All @@ -47,7 +47,7 @@ test('mix query and mutation', async () => {
});

test('merge', async () => {
type Context = {};
type Context = object;
const t = initTRPC.context<Context>().create();
const mergeRouters = t.mergeRouters;

Expand Down Expand Up @@ -365,7 +365,7 @@ describe('integration tests', () => {
});

describe('createCaller()', () => {
type Context = {};
type Context = object;
const t = initTRPC.context<Context>().create();

const router = t.router({
Expand Down Expand Up @@ -410,7 +410,7 @@ describe('createCaller()', () => {
});

describe('createCaller()', () => {
type Context = {};
type Context = object;
const t = initTRPC.context<Context>().create();

const router = t.router({
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/server/inferenceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export type DeepBrand<T> = IsNever<T> extends true

export type RequiredKeys<T> = Extract<
{
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
[K in keyof T]-?: object extends Pick<T, K> ? never : K;
}[keyof T],
keyof T
>;
Expand Down
7 changes: 6 additions & 1 deletion packages/tests/server/initTRPC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ test('config types', () => {

t._config;
// ^?
expectTypeOf<typeof t._config.$types.ctx>().toEqualTypeOf<{}>();
expectTypeOf<typeof t._config.$types.ctx>().toEqualTypeOf<object>();
expectTypeOf<typeof t._config.$types.meta>().toEqualTypeOf<object>();

// eslint-disable-next-line @typescript-eslint/ban-types
expectTypeOf<typeof t._config.$types.meta>().toEqualTypeOf<{}>();
// eslint-disable-next-line @typescript-eslint/ban-types
expectTypeOf<typeof t._config.$types.meta>().toEqualTypeOf<{}>();
}

Expand Down
2 changes: 2 additions & 0 deletions packages/tests/server/interop/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types */

/* eslint-disable @typescript-eslint/no-empty-function */

/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down
2 changes: 2 additions & 0 deletions packages/tests/server/interop/react/__testHelpers.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types */

/* eslint-disable @typescript-eslint/no-empty-function */
import { routerToServerAndClientNew } from '../../___testHelpers';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types */

/* eslint-disable @typescript-eslint/no-unused-vars */
// IMPORTANT:
// needs to be imported from compiled output otherwise we get a false-positive
Expand All @@ -8,7 +10,6 @@ import { z } from 'zod';
// https://github.com/trpc/trpc/issues/949
// https://github.com/trpc/trpc/pull/955
test('inferProcedureFromInput regression', async () => {
// eslint-disable-next-line @typescript-eslint/ban-types
type Context = {};
const appRouter = trpc
.router<Context>()
Expand Down
4 changes: 2 additions & 2 deletions packages/tests/server/jsonify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ describe('no transformer specified', () => {
// ^?
expectTypeOf(result).toMatchTypeOf<{
date: string;
map: {};
set: {};
map: object;
set: object;
}>();
expectTypeOf(result.arrayWithUndefined);
// ^?
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/server/router.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './___packages';
import { initTRPC } from '@trpc/server/src/core';

const t = initTRPC.create<{}>();
const t = initTRPC.create();

describe('router', () => {
test('is a reserved word', async () => {
Expand Down

0 comments on commit a02430d

Please sign in to comment.