I've been attempting to use this definition:
import { GraphQLScalarType } from 'graphql';
import { Type } from '@nestjs/common';
export function createFilterClass<T extends typeof GraphQLScalarType>(
FilterType: Type<T>
) {
// ...
}
However, all my efforts have been unsuccessful:
import { GraphQLString } from 'graphql';
import { createFilterClass } from './filter-class';
const c = createFilterClass(GraphQLString);
/* Argument of type 'GraphQLScalarType<string, string>' is
not assignable to parameter of type 'Type<typeof GraphQLScalarType>'.
Type 'GraphQLScalarType<string, string>' is missing the following
properties from type 'Type<typeof GraphQLScalarType>':
apply, call, bind, prototype, and 4 more. ts(2345)
*/
const c = createFilterClass(GraphQLString);
/* Argument of type 'string' is not assignable to
parameter of type 'Type<typeof GraphQLScalarType>'.
Type 'string' is not assignable to type 'Type<typeof GraphQLScalarType>'. ts(2345)
*/
Please note that the use of Type<T>
within createFilterClass
is necessary, as without it, the following line will result in an error:
@Field(() => FilterType, { nullable: true }) // Argument of type '{ nullable: true; }' is not assignable to parameter of type 'FieldOptionsExtractor<T>'. ts(2345)
myField?: T;