Skip to content

Commit

Permalink
function overloading
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed May 14, 2021
1 parent aeb3a7d commit db11cba
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 34 deletions.
12 changes: 6 additions & 6 deletions src/jsutils/didYouMean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>): string;
// eslint-disable-next-line no-redeclare
declare function didYouMean(
export function didYouMean(suggestions: ReadonlyArray<string>): string;
export function didYouMean(
subMessage: string,
suggestions: ReadonlyArray<string>,
): string;

// eslint-disable-next-line no-redeclare
export function didYouMean(firstArg, secondArg) {
export function didYouMean(
firstArg: string | ReadonlyArray<string>,
secondArg?: ReadonlyArray<string>,
) {
const [subMessage, suggestionsArg] =
typeof firstArg === 'string'
? [firstArg, secondArg]
Expand Down
10 changes: 3 additions & 7 deletions src/jsutils/isAsyncIterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>;

// eslint-disable-next-line no-redeclare
export function isAsyncIterable(maybeAsyncIterable) {
export function isAsyncIterable(
maybeAsyncIterable: unknown,
): maybeAsyncIterable is AsyncIterable<unknown> {
return typeof maybeAsyncIterable?.[Symbol.asyncIterator] === 'function';
}
10 changes: 3 additions & 7 deletions src/jsutils/isIterableObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>;

// eslint-disable-next-line no-redeclare
export function isIterableObject(maybeIterable: unknown): boolean {
export function isIterableObject(
maybeIterable: unknown,
): maybeIteratable is Iterable<unknown> {
return (
typeof maybeIterable === 'object' &&
typeof maybeIterable?.[Symbol.iterator] === 'function'
Expand Down
9 changes: 3 additions & 6 deletions src/jsutils/toObjMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import type {
ReadOnlyObjMapLike,
} from './ObjMap';

/* eslint-disable no-redeclare */
declare function toObjMap<T>(obj: ObjMapLike<T>): ObjMap<T>;
declare function toObjMap<T>(obj: ReadOnlyObjMapLike<T>): ReadOnlyObjMap<T>;

export function toObjMap(obj) {
/* eslint-enable no-redeclare */
export function toObjMap<T>(obj: ObjMapLike<T>): ObjMap<T>;
export function toObjMap<T>(obj: ReadOnlyObjMapLike<T>): ReadOnlyObjMap<T>;
export function toObjMap<T>(obj: ObjMapLike<T> | ReadOnlyObjMapLike<T>) {
if (Object.getPrototypeOf(obj) === null) {
return obj;
}
Expand Down
14 changes: 6 additions & 8 deletions src/utilities/typeFromAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> | void;
declare function typeFromAST(
): GraphQLList<any> | undefined;
export function typeFromAST(
schema: GraphQLSchema,
typeNode: NonNullTypeNode,
): GraphQLNonNull<any> | void;
): GraphQLNonNull<any> | undefined;
export function typeFromAST(schema, typeNode) {
/* eslint-enable no-redeclare */
let innerType;
if (typeNode.kind === Kind.LIST_TYPE) {
innerType = typeFromAST(schema, typeNode.type);
Expand Down

0 comments on commit db11cba

Please sign in to comment.