Skip to content

Commit

Permalink
convert : (flow) with extends (TS)
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Oct 27, 2020
1 parent 4fdd660 commit c7af53c
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/language/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ShapeMap<O, F> = $Shape<$ObjMap<O, F>>;
* A visitor is comprised of visit functions, which are called on each node
* during the visitor's traversal.
*/
export type VisitFn<TAnyNode, TVisitedNode: TAnyNode = TAnyNode> = (
export type VisitFn<TAnyNode, TVisitedNode extends TAnyNode = TAnyNode> = (
// The current node being visiting.
node: TVisitedNode,
// The index or key to this node from the parent node or Array.
Expand Down
2 changes: 1 addition & 1 deletion src/subscription/__tests__/subscribe-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const EmailEventType = new GraphQLObjectType({

const emailSchema = emailSchemaWithResolvers();

function emailSchemaWithResolvers<T: unknown>(
function emailSchemaWithResolvers<T extends unknown>(
subscribeFn?: (T) => unknown,
resolveFn?: (T) => unknown,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/type/__tests__/validation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const SomeInputObjectType = assertInputObjectType(

const SomeDirective = assertDirective(SomeSchema.getDirective('SomeDirective'));

function withModifiers<T: GraphQLNamedType>(
function withModifiers<T extends GraphQLNamedType>(
type: T,
): Array<T | GraphQLList<T> | GraphQLNonNull<T | GraphQLList<T>>> {
return [
Expand Down
10 changes: 5 additions & 5 deletions src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ export function assertAbstractType(type: unknown): GraphQLAbstractType {
* })
*
*/
export class GraphQLList<+T: GraphQLType> {
+ofType: T;
export class GraphQLList<T extends GraphQLType> {
readonly ofType: T;

constructor(ofType: T) {
devAssert(
Expand Down Expand Up @@ -390,8 +390,8 @@ export class GraphQLList<+T: GraphQLType> {
*
* Note: the enforcement of non-nullability occurs within the executor.
*/
export class GraphQLNonNull<+T: GraphQLNullableType> {
+ofType: T;
export class GraphQLNonNull<T extends GraphQLNullableType> {
readonly ofType: T;

constructor(ofType: T) {
devAssert(
Expand Down Expand Up @@ -458,7 +458,7 @@ export function assertNullableType(type: unknown): GraphQLNullableType {

/* eslint-disable no-redeclare */
declare function getNullableType(type: void | null): void;
declare function getNullableType<T: GraphQLNullableType>(type: T): T;
declare function getNullableType<T extends GraphQLNullableType>(type: T): T;
declare function getNullableType<T>(type: GraphQLNonNull<T>): T;
export function getNullableType(type) {
/* eslint-enable no-redeclare */
Expand Down
4 changes: 2 additions & 2 deletions src/type/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ type SDLDefinedObject<T, K> = {
readonly extensionASTNodes?: Maybe<ReadonlyArray<K>>,
};

function getAllNodes<T: ASTNode, K: ASTNode>(
function getAllNodes<T extends ASTNode, K extends ASTNode>(
object: SDLDefinedObject<T, K>,
): ReadonlyArray<T | K> {
const { astNode, extensionASTNodes } = object;
Expand All @@ -628,7 +628,7 @@ function getAllNodes<T: ASTNode, K: ASTNode>(
: extensionASTNodes ?? [];
}

function getAllSubNodes<T: ASTNode, K: ASTNode, L: ASTNode>(
function getAllSubNodes<T extends ASTNode, K extends ASTNode, L extends ASTNode>(
object: SDLDefinedObject<T, K>,
getter: (T | K) => Maybe<(L | ReadonlyArray<L>)>,
): ReadonlyArray<L> {
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/extendSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function extendSchemaImpl(
// Below are functions used for producing this schema that have closed over
// this scope and have access to the schema, cache, and newly defined types.

function replaceType<T: GraphQLType>(type: T): T {
function replaceType<T extends GraphQLType>(type: T): T {
if (isListType(type)) {
// $FlowFixMe[incompatible-return]
return new GraphQLList(replaceType(type.ofType));
Expand All @@ -232,7 +232,7 @@ export function extendSchemaImpl(
return replaceNamedType(type);
}

function replaceNamedType<T: GraphQLNamedType>(type: T): T {
function replaceNamedType<T extends GraphQLNamedType>(type: T): T {
// Note: While this could make early assertions to get the correctly
// typed values, that would throw immediately while type system
// validation with validateSchema() will produce more actionable results.
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/findBreakingChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ function stringifyValue(value: unknown, type: GraphQLInputType): string {
return print(sortedAST);
}

function diff<T: { name: string }>(
function diff<T extends { name: string }>(
oldArray: ReadonlyArray<T>,
newArray: ReadonlyArray<T>,
): {
Expand Down
6 changes: 3 additions & 3 deletions src/utilities/getIntrospectionQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ export type IntrospectionInputObjectType = {
};

export type IntrospectionListTypeRef<
T: IntrospectionTypeRef = IntrospectionTypeRef,
T extends IntrospectionTypeRef = IntrospectionTypeRef,
> = {
readonly kind: 'LIST',
readonly ofType: T,
};

export type IntrospectionNonNullTypeRef<
T: IntrospectionTypeRef = IntrospectionTypeRef,
T extends IntrospectionTypeRef = IntrospectionTypeRef,
> = {
readonly kind: 'NON_NULL',
readonly ofType: T,
Expand Down Expand Up @@ -261,7 +261,7 @@ export type IntrospectionInputTypeRef =
>;

export type IntrospectionNamedTypeRef<
T: IntrospectionType = IntrospectionType,
T extends IntrospectionType = IntrospectionType,
> = {
readonly kind: $PropertyType<T, 'kind'>,
readonly name: string,
Expand Down
12 changes: 6 additions & 6 deletions src/utilities/lexicographicSortSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function lexicographicSortSchema(schema: GraphQLSchema): GraphQLSchema {
subscription: replaceMaybeType(schemaConfig.subscription),
});

function replaceType<T: GraphQLType>(type: T): T {
function replaceType<T extends GraphQLType>(type: T): T {
if (isListType(type)) {
// $FlowFixMe[incompatible-return]
return new GraphQLList(replaceType(type.ofType));
Expand All @@ -66,11 +66,11 @@ export function lexicographicSortSchema(schema: GraphQLSchema): GraphQLSchema {
return replaceNamedType(type);
}

function replaceNamedType<T: GraphQLNamedType>(type: T): T {
function replaceNamedType<T extends GraphQLNamedType>(type: T): T {
return ((typeMap[type.name]: any): T);
}

function replaceMaybeType<T: ?GraphQLNamedType>(maybeType: T): T {
function replaceMaybeType<T extends ?GraphQLNamedType>(maybeType: T): T {
return maybeType && replaceNamedType(maybeType);
}

Expand Down Expand Up @@ -105,11 +105,11 @@ export function lexicographicSortSchema(schema: GraphQLSchema): GraphQLSchema {
}));
}

function sortTypes<T: GraphQLNamedType>(arr: ReadonlyArray<T>): Array<T> {
function sortTypes<T extends GraphQLNamedType>(arr: ReadonlyArray<T>): Array<T> {
return sortByName(arr).map(replaceNamedType);
}

function sortNamedType<T: GraphQLNamedType>(type: T) {
function sortNamedType<T extends GraphQLNamedType>(type: T) {
if (isScalarType(type) || isIntrospectionType(type)) {
return type;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ function sortObjMap<T, R>(map: ObjMap<T>, sortValueFn?: (T) => R): ObjMap<R> {
return sortedMap;
}

function sortByName<T: { readonly name: string }>(
function sortByName<T extends { readonly name: string }>(
array: ReadonlyArray<T>,
): Array<T> {
return sortBy(array, (obj) => obj.name);
Expand Down

0 comments on commit c7af53c

Please sign in to comment.