From db11cba368d9ebfbcb377322b518bfdd9d6066a8 Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Fri, 14 May 2021 13:36:03 -0400 Subject: [PATCH] function overloading --- src/jsutils/didYouMean.ts | 12 ++++++------ src/jsutils/isAsyncIterable.ts | 10 +++------- src/jsutils/isIterableObject.ts | 10 +++------- src/jsutils/toObjMap.ts | 9 +++------ src/utilities/typeFromAST.ts | 14 ++++++-------- 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/jsutils/didYouMean.ts b/src/jsutils/didYouMean.ts index 1efe2c80ce..4f15678975 100644 --- a/src/jsutils/didYouMean.ts +++ b/src/jsutils/didYouMean.ts @@ -3,15 +3,15 @@ const MAX_SUGGESTIONS = 5; /** * Given [ A, B, C ] return ' Did you mean A, B, or C?'. */ -declare function didYouMean(suggestions: ReadonlyArray): string; -// eslint-disable-next-line no-redeclare -declare function didYouMean( +export function didYouMean(suggestions: ReadonlyArray): string; +export function didYouMean( subMessage: string, suggestions: ReadonlyArray, ): string; - -// eslint-disable-next-line no-redeclare -export function didYouMean(firstArg, secondArg) { +export function didYouMean( + firstArg: string | ReadonlyArray, + secondArg?: ReadonlyArray, +) { const [subMessage, suggestionsArg] = typeof firstArg === 'string' ? [firstArg, secondArg] diff --git a/src/jsutils/isAsyncIterable.ts b/src/jsutils/isAsyncIterable.ts index 3424ef911d..8f26130003 100644 --- a/src/jsutils/isAsyncIterable.ts +++ b/src/jsutils/isAsyncIterable.ts @@ -2,12 +2,8 @@ * Returns true if the provided object implements the AsyncIterator protocol via * implementing a `Symbol.asyncIterator` method. */ -declare function isAsyncIterable( - value: unknown, - // $FlowFixMe[invalid-in-rhs] -): value is AsyncIterable; - -// eslint-disable-next-line no-redeclare -export function isAsyncIterable(maybeAsyncIterable) { +export function isAsyncIterable( + maybeAsyncIterable: unknown, +): maybeAsyncIterable is AsyncIterable { return typeof maybeAsyncIterable?.[Symbol.asyncIterator] === 'function'; } diff --git a/src/jsutils/isIterableObject.ts b/src/jsutils/isIterableObject.ts index 4036eb513d..a4e7d13966 100644 --- a/src/jsutils/isIterableObject.ts +++ b/src/jsutils/isIterableObject.ts @@ -14,13 +14,9 @@ * isIterableObject({ key: 'value' }) // false * isIterableObject({ length: 1, 0: 'Alpha' }) // false */ -declare function isIterableObject( - value: unknown, - // $FlowFixMe[invalid-in-rhs] -): value is Iterable; - -// eslint-disable-next-line no-redeclare -export function isIterableObject(maybeIterable: unknown): boolean { +export function isIterableObject( + maybeIterable: unknown, +): maybeIteratable is Iterable { return ( typeof maybeIterable === 'object' && typeof maybeIterable?.[Symbol.iterator] === 'function' diff --git a/src/jsutils/toObjMap.ts b/src/jsutils/toObjMap.ts index 69ac0d06ad..63d6c27eed 100644 --- a/src/jsutils/toObjMap.ts +++ b/src/jsutils/toObjMap.ts @@ -5,12 +5,9 @@ import type { ReadOnlyObjMapLike, } from './ObjMap'; -/* eslint-disable no-redeclare */ -declare function toObjMap(obj: ObjMapLike): ObjMap; -declare function toObjMap(obj: ReadOnlyObjMapLike): ReadOnlyObjMap; - -export function toObjMap(obj) { - /* eslint-enable no-redeclare */ +export function toObjMap(obj: ObjMapLike): ObjMap; +export function toObjMap(obj: ReadOnlyObjMapLike): ReadOnlyObjMap; +export function toObjMap(obj: ObjMapLike | ReadOnlyObjMapLike) { if (Object.getPrototypeOf(obj) === null) { return obj; } diff --git a/src/utilities/typeFromAST.ts b/src/utilities/typeFromAST.ts index 8e7f1dafb1..7a653d0e03 100644 --- a/src/utilities/typeFromAST.ts +++ b/src/utilities/typeFromAST.ts @@ -20,21 +20,19 @@ import { GraphQLList, GraphQLNonNull } from '../type/definition'; * the type called "User" found in the schema. If a type called "User" is not * found in the schema, then undefined will be returned. */ -/* eslint-disable no-redeclare */ -declare function typeFromAST( +export function typeFromAST( schema: GraphQLSchema, typeNode: NamedTypeNode, -): GraphQLNamedType | void; -declare function typeFromAST( +): GraphQLNamedType | undefined; +export function typeFromAST( schema: GraphQLSchema, typeNode: ListTypeNode, -): GraphQLList | void; -declare function typeFromAST( +): GraphQLList | undefined; +export function typeFromAST( schema: GraphQLSchema, typeNode: NonNullTypeNode, -): GraphQLNonNull | void; +): GraphQLNonNull | undefined; export function typeFromAST(schema, typeNode) { - /* eslint-enable no-redeclare */ let innerType; if (typeNode.kind === Kind.LIST_TYPE) { innerType = typeFromAST(schema, typeNode.type);