Skip to content

Commit 7397d82

Browse files
committed
fix: eliminate some unnecessary any casts
1 parent 5efa7c1 commit 7397d82

16 files changed

Lines changed: 59 additions & 53 deletions

packages/entity-cache-adapter-redis/src/__tests__/GenericRedisCacher-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe(GenericRedisCacher, () => {
109109
return pipeline;
110110
},
111111
);
112-
when(mockPipeline.exec()).thenResolve({} as any);
112+
when(mockPipeline.exec()).thenResolve([]);
113113
const pipeline = instance(mockPipeline);
114114

115115
const mockRedisClient = mock<Redis>();
@@ -154,7 +154,7 @@ describe(GenericRedisCacher, () => {
154154
return pipeline;
155155
},
156156
);
157-
when(mockPipeline.exec()).thenResolve({} as any);
157+
when(mockPipeline.exec()).thenResolve([]);
158158
const pipeline = instance(mockPipeline);
159159

160160
const mockRedisClient = mock<Redis>();

packages/entity-database-adapter-knex/src/PostgresEntityDatabaseAdapter.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,7 @@ export class PostgresEntityDatabaseAdapter<
215215
bindings: object | any[],
216216
querySelectionModifiers: TableQuerySelectionModifiersWithOrderByRaw,
217217
): Promise<object[]> {
218-
let query = queryInterface
219-
.select()
220-
.from(tableName)
221-
.whereRaw(rawWhereClause, bindings as any);
218+
let query = queryInterface.select().from(tableName).whereRaw(rawWhereClause, bindings);
222219
query = this.applyQueryModifiersToQueryOrderByRaw(query, querySelectionModifiers);
223220
return await wrapNativePostgresCallAsync(() => query);
224221
}

packages/entity-database-adapter-knex/src/__tests__/EntityFields-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BigIntField, JSONArrayField, MaybeJSONArrayField } from '../EntityField
44

55
describeFieldTestCase(
66
new JSONArrayField({ columnName: 'wat' }),
7-
[[[1, 2]] as any, [['hello']] as any],
7+
[[[1, 2]], [['hello']]],
88
[1, 'hello'],
99
);
1010
describeFieldTestCase(

packages/entity-database-adapter-knex/src/__tests__/SQLOperator-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ describe('SQLOperator', () => {
280280

281281
it('handles non-SupportedSQLValue types gracefully', () => {
282282
const fragment = new SQLFragment('SELECT * FROM test WHERE field = ? AND field2 = ?', [
283-
{ type: 'value', value: new Error('wat') as any },
283+
{ type: 'value', value: new Error('wat') },
284284
{ type: 'value', value: Object.create(null) },
285285
]);
286286

packages/entity-example/src/app.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApolloServer } from '@apollo/server';
1+
import { ApolloServer, type BaseContext } from '@apollo/server';
22
import { koaMiddleware } from '@as-integrations/koa';
33
import { EntityCompanionProvider } from '@expo/entity';
44
import { bodyParser } from '@koa/bodyparser';
@@ -23,6 +23,10 @@ export type ExampleState = {
2323
entityCompanionProvider: EntityCompanionProvider; // entityCompanionMiddleware
2424
};
2525

26+
export interface GraphQLContext extends BaseContext {
27+
viewerContext: ExampleViewerContext;
28+
}
29+
2630
export async function createAppAsync(): Promise<Koa<ExampleState, ExampleContext>> {
2731
const app = new Koa<ExampleState, ExampleContext>();
2832

@@ -44,15 +48,15 @@ export async function createAppAsync(): Promise<Koa<ExampleState, ExampleContext
4448
router.use(notesRouter.routes());
4549

4650
// GraphQL routes
47-
const server = new ApolloServer({
51+
const server = new ApolloServer<GraphQLContext>({
4852
typeDefs,
4953
resolvers,
5054
});
5155
await server.start();
5256
router.post(
5357
'/graphql',
54-
// https://github.com/apollographql/apollo-server/issues/7625
55-
koaMiddleware(server as any, {
58+
// @ts-expect-error - @as-integrations/koa peers on @apollo/server ^4 (CJS types) but we use v5 (ESM types)
59+
koaMiddleware<GraphQLContext, ExampleState, ExampleContext>(server, {
5660
context: async ({ ctx }: { ctx: ExampleContext }) => ({
5761
viewerContext: ctx.state.viewerContext,
5862
}),

packages/entity/src/AuthorizationResultBasedEntityAssociationLoader.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class AuthorizationResultBasedEntityAssociationLoader<
1616
TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>,
1717
TViewerContext extends ViewerContext,
1818
TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>,
19-
TSelectedFields extends keyof TFields,
19+
TSelectedFields extends keyof TFields = keyof TFields,
2020
> {
2121
constructor(
2222
private readonly entity: TEntity,
@@ -123,10 +123,7 @@ export class AuthorizationResultBasedEntityAssociationLoader<
123123
.getViewerScopedEntityCompanionForClass(associatedEntityClass)
124124
.getLoaderFactory()
125125
.forLoad(this.queryContext, { previousValue: null, cascadingDeleteCause: null });
126-
return await loader.loadManyByFieldEqualingAsync(
127-
associatedEntityFieldContainingThisID,
128-
thisID as any,
129-
);
126+
return await loader.loadManyByFieldEqualingAsync(associatedEntityFieldContainingThisID, thisID);
130127
}
131128

132129
/**
@@ -178,7 +175,7 @@ export class AuthorizationResultBasedEntityAssociationLoader<
178175
.forLoad(this.queryContext, { previousValue: null, cascadingDeleteCause: null });
179176
return await loader.loadByFieldEqualingAsync(
180177
associatedEntityLookupByField,
181-
associatedFieldValue as any,
178+
associatedFieldValue,
182179
);
183180
}
184181

@@ -232,7 +229,7 @@ export class AuthorizationResultBasedEntityAssociationLoader<
232229
.forLoad(this.queryContext, { previousValue: null, cascadingDeleteCause: null });
233230
return await loader.loadManyByFieldEqualingAsync(
234231
associatedEntityLookupByField,
235-
associatedFieldValue as any,
232+
associatedFieldValue,
236233
);
237234
}
238235

packages/entity/src/AuthorizationResultBasedEntityMutator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ export class AuthorizationResultBasedDeleteMutator<
986986
.loadManyByFieldEqualingAsync(
987987
fieldName,
988988
association.associatedEntityLookupByField
989-
? entity.getField(association.associatedEntityLookupByField as any)
989+
? entity.getField(association.associatedEntityLookupByField)
990990
: entity.getID(),
991991
),
992992
);

packages/entity/src/EnforcingEntityLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class EnforcingEntityLoader<
2424
TEntity,
2525
TSelectedFields
2626
>,
27-
TSelectedFields extends keyof TFields,
27+
TSelectedFields extends keyof TFields = keyof TFields,
2828
> {
2929
constructor(
3030
private readonly entityLoader: AuthorizationResultBasedEntityLoader<

packages/entity/src/EntityFieldDefinition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export interface EntityAssociationDefinition<
103103
* Field by which to load the instance of associatedEntityClass. If not provided, the
104104
* associatedEntityClass instance is fetched by its ID.
105105
*/
106-
associatedEntityLookupByField?: keyof TAssociatedFields;
106+
associatedEntityLookupByField?: TAssociatedSelectedFields;
107107

108108
/**
109109
* What action to perform on the entity at the other end of this edge when the entity on the source end of

packages/entity/src/__tests__/ComposedCacheAdapter-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ describe(ComposedEntityCacheAdapter, () => {
289289
const { cacheAdapter } = makeTestCacheAdapters();
290290
const results = await cacheAdapter.loadManyAsync(
291291
new SingleFieldHolder<BlahFields, 'id', 'id'>('id'),
292-
[] as any,
292+
[] as readonly SingleFieldValueHolder<BlahFields, 'id'>[],
293293
);
294294
expect(results.size).toBe(0);
295295
});
@@ -298,7 +298,7 @@ describe(ComposedEntityCacheAdapter, () => {
298298
const cacheAdapter = new ComposedEntityCacheAdapter<BlahFields, 'id'>([]);
299299
const results = await cacheAdapter.loadManyAsync(
300300
new SingleFieldHolder<BlahFields, 'id', 'id'>('id'),
301-
[] as any,
301+
[] as readonly SingleFieldValueHolder<BlahFields, 'id'>[],
302302
);
303303
expect(results.size).toBe(0);
304304
});
@@ -430,7 +430,7 @@ describe(ComposedEntityCacheAdapter, () => {
430430

431431
await cacheAdapter.invalidateManyAsync(
432432
new SingleFieldHolder<BlahFields, 'id', 'id'>('id'),
433-
[] as any,
433+
[] as readonly SingleFieldValueHolder<BlahFields, 'id'>[],
434434
);
435435
});
436436
});

0 commit comments

Comments
 (0)