From 9ca3492c634cd7880ebfa4b2392d7c620e0bd2c5 Mon Sep 17 00:00:00 2001 From: Dotan Simha Date: Fri, 5 Jun 2020 10:08:48 +0300 Subject: [PATCH 1/3] Fixes for `d.ts` files --- src/__fixtures__/index.d.ts | 4 ++++ src/error/GraphQLError.d.ts | 2 +- src/jsutils/ObjMap.d.ts | 15 +++++++++++++++ src/jsutils/didYouMean.d.ts | 4 ++++ src/jsutils/identityFunc.d.ts | 1 + src/jsutils/inspect.d.ts | 1 + src/jsutils/instanceOf.d.ts | 1 + src/jsutils/invariant.d.ts | 1 + src/jsutils/isCollection.d.ts | 1 + src/jsutils/isObjectLike.d.ts | 1 + src/jsutils/nodejsCustomInspectSymbol.d.ts | 4 ++++ src/jsutils/suggestionList.d.ts | 4 ++++ src/jsutils/toObjMap.d.ts | 13 +++++++++++++ 13 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/__fixtures__/index.d.ts create mode 100644 src/jsutils/ObjMap.d.ts create mode 100644 src/jsutils/didYouMean.d.ts create mode 100644 src/jsutils/identityFunc.d.ts create mode 100644 src/jsutils/inspect.d.ts create mode 100644 src/jsutils/instanceOf.d.ts create mode 100644 src/jsutils/invariant.d.ts create mode 100644 src/jsutils/isCollection.d.ts create mode 100644 src/jsutils/isObjectLike.d.ts create mode 100644 src/jsutils/nodejsCustomInspectSymbol.d.ts create mode 100644 src/jsutils/suggestionList.d.ts create mode 100644 src/jsutils/toObjMap.d.ts diff --git a/src/__fixtures__/index.d.ts b/src/__fixtures__/index.d.ts new file mode 100644 index 0000000000..0e281da754 --- /dev/null +++ b/src/__fixtures__/index.d.ts @@ -0,0 +1,4 @@ +export declare const bigSchemaSDL: string; +export declare const bigSchemaIntrospectionResult: Record; +export declare const kitchenSinkSDL: string; +export declare const kitchenSinkQuery: string; diff --git a/src/error/GraphQLError.d.ts b/src/error/GraphQLError.d.ts index 4e741f9796..99001fd26f 100644 --- a/src/error/GraphQLError.d.ts +++ b/src/error/GraphQLError.d.ts @@ -13,7 +13,7 @@ import { SourceLocation } from '../language/location'; export class GraphQLError extends Error { constructor( message: string, - nodes?: ReadonlyArray | ASTNode, + nodes?: Maybe | ASTNode>, source?: Maybe, positions?: Maybe>, path?: Maybe>, diff --git a/src/jsutils/ObjMap.d.ts b/src/jsutils/ObjMap.d.ts new file mode 100644 index 0000000000..bc7a6362cf --- /dev/null +++ b/src/jsutils/ObjMap.d.ts @@ -0,0 +1,15 @@ +export interface ObjMap { + [key: string]: T; + __proto__: never; +} + +export type ObjMapLike = ObjMap | { [key: string]: T }; + +export interface ReadOnlyObjMap { + readonly [key: string]: T; + __proto__: never; +} + +export type ReadOnlyObjMapLike = + | ReadOnlyObjMap + | { readonly [key: string]: T }; diff --git a/src/jsutils/didYouMean.d.ts b/src/jsutils/didYouMean.d.ts new file mode 100644 index 0000000000..ceac122303 --- /dev/null +++ b/src/jsutils/didYouMean.d.ts @@ -0,0 +1,4 @@ +export default function didYouMean( + firstArg: string | ReadonlyArray, + secondArg?: ReadonlyArray, +): string; diff --git a/src/jsutils/identityFunc.d.ts b/src/jsutils/identityFunc.d.ts new file mode 100644 index 0000000000..0fa230b6e2 --- /dev/null +++ b/src/jsutils/identityFunc.d.ts @@ -0,0 +1 @@ +export default function identityFunc(x?: T): T; diff --git a/src/jsutils/inspect.d.ts b/src/jsutils/inspect.d.ts new file mode 100644 index 0000000000..e4bb5ada4f --- /dev/null +++ b/src/jsutils/inspect.d.ts @@ -0,0 +1 @@ +export default function inspect(value: any): string; diff --git a/src/jsutils/instanceOf.d.ts b/src/jsutils/instanceOf.d.ts new file mode 100644 index 0000000000..e1312be347 --- /dev/null +++ b/src/jsutils/instanceOf.d.ts @@ -0,0 +1 @@ +export default function instanceOf(value: any, constructor: any): boolean; diff --git a/src/jsutils/invariant.d.ts b/src/jsutils/invariant.d.ts new file mode 100644 index 0000000000..441b413953 --- /dev/null +++ b/src/jsutils/invariant.d.ts @@ -0,0 +1 @@ +export default function invariant(condition: any, message?: string): void; diff --git a/src/jsutils/isCollection.d.ts b/src/jsutils/isCollection.d.ts new file mode 100644 index 0000000000..506326c2fc --- /dev/null +++ b/src/jsutils/isCollection.d.ts @@ -0,0 +1 @@ +export default function isCollection(obj: any): boolean; diff --git a/src/jsutils/isObjectLike.d.ts b/src/jsutils/isObjectLike.d.ts new file mode 100644 index 0000000000..05e69785b3 --- /dev/null +++ b/src/jsutils/isObjectLike.d.ts @@ -0,0 +1 @@ +export default function isObjectLike(value: any): boolean; diff --git a/src/jsutils/nodejsCustomInspectSymbol.d.ts b/src/jsutils/nodejsCustomInspectSymbol.d.ts new file mode 100644 index 0000000000..84ee6f3770 --- /dev/null +++ b/src/jsutils/nodejsCustomInspectSymbol.d.ts @@ -0,0 +1,4 @@ +// istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) +declare const nodejsCustomInspectSymbol: symbol | undefined; + +export default nodejsCustomInspectSymbol; diff --git a/src/jsutils/suggestionList.d.ts b/src/jsutils/suggestionList.d.ts new file mode 100644 index 0000000000..560c1c5355 --- /dev/null +++ b/src/jsutils/suggestionList.d.ts @@ -0,0 +1,4 @@ +export default function suggestionList( + input: string, + options: ReadonlyArray, +): Array; diff --git a/src/jsutils/toObjMap.d.ts b/src/jsutils/toObjMap.d.ts new file mode 100644 index 0000000000..b17aecfaf5 --- /dev/null +++ b/src/jsutils/toObjMap.d.ts @@ -0,0 +1,13 @@ +import { + ObjMap, + ObjMapLike, + ReadOnlyObjMap, + ReadOnlyObjMapLike, +} from './ObjMap'; + +// eslint-disable-next-line import/export +export default function toObjMap(obj: ObjMapLike): ObjMap; +// eslint-disable-next-line import/export +export default function toObjMap( + obj: ReadOnlyObjMapLike, +): ReadOnlyObjMap; From 90cc94e87e0ce3a673b4097112c39eed86ff9cf6 Mon Sep 17 00:00:00 2001 From: Dotan Simha Date: Sun, 7 Jun 2020 09:14:56 +0300 Subject: [PATCH 2/3] Update src/__fixtures__/index.d.ts Co-authored-by: Ivan Goncharov --- src/__fixtures__/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__fixtures__/index.d.ts b/src/__fixtures__/index.d.ts index 0e281da754..b51118abf7 100644 --- a/src/__fixtures__/index.d.ts +++ b/src/__fixtures__/index.d.ts @@ -1,4 +1,4 @@ export declare const bigSchemaSDL: string; -export declare const bigSchemaIntrospectionResult: Record; +export declare const bigSchemaIntrospectionResult: { data: unknown }; export declare const kitchenSinkSDL: string; export declare const kitchenSinkQuery: string; From 5bc614100dfffd4c66e3480340bc9a9118a0d5b3 Mon Sep 17 00:00:00 2001 From: Dotan Simha Date: Sun, 7 Jun 2020 09:19:34 +0300 Subject: [PATCH 3/3] fixes --- src/jsutils/didYouMean.d.ts | 12 +++++++++--- src/jsutils/identityFunc.d.ts | 3 +++ src/jsutils/inspect.d.ts | 3 +++ src/jsutils/instanceOf.d.ts | 4 ++++ src/jsutils/isCollection.d.ts | 21 +++++++++++++++++++++ src/jsutils/isObjectLike.d.ts | 4 ++++ src/jsutils/nodejsCustomInspectSymbol.d.ts | 1 - src/jsutils/suggestionList.d.ts | 4 ++++ src/jsutils/toObjMap.d.ts | 10 ++++------ 9 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/jsutils/didYouMean.d.ts b/src/jsutils/didYouMean.d.ts index ceac122303..299f5af5e3 100644 --- a/src/jsutils/didYouMean.d.ts +++ b/src/jsutils/didYouMean.d.ts @@ -1,4 +1,10 @@ -export default function didYouMean( - firstArg: string | ReadonlyArray, - secondArg?: ReadonlyArray, +/** + * Given [ A, B, C ] return ' Did you mean A, B, or C?'. + */ +declare function didYouMean(suggestions: ReadonlyArray): string; +declare function didYouMean( + subMessage: string, + suggestions: ReadonlyArray, ): string; + +export default didYouMean; diff --git a/src/jsutils/identityFunc.d.ts b/src/jsutils/identityFunc.d.ts index 0fa230b6e2..af766f2dbb 100644 --- a/src/jsutils/identityFunc.d.ts +++ b/src/jsutils/identityFunc.d.ts @@ -1 +1,4 @@ +/** + * Returns the first argument it receives. + */ export default function identityFunc(x?: T): T; diff --git a/src/jsutils/inspect.d.ts b/src/jsutils/inspect.d.ts index e4bb5ada4f..76970a8ffb 100644 --- a/src/jsutils/inspect.d.ts +++ b/src/jsutils/inspect.d.ts @@ -1 +1,4 @@ +/** + * Used to print values in error messages. + */ export default function inspect(value: any): string; diff --git a/src/jsutils/instanceOf.d.ts b/src/jsutils/instanceOf.d.ts index e1312be347..c80c7c74cd 100644 --- a/src/jsutils/instanceOf.d.ts +++ b/src/jsutils/instanceOf.d.ts @@ -1 +1,5 @@ +/** + * A replacement for instanceof which includes an error warning when multi-realm + * constructors are detected. + */ export default function instanceOf(value: any, constructor: any): boolean; diff --git a/src/jsutils/isCollection.d.ts b/src/jsutils/isCollection.d.ts index 506326c2fc..ee1a5d184c 100644 --- a/src/jsutils/isCollection.d.ts +++ b/src/jsutils/isCollection.d.ts @@ -1 +1,22 @@ +/** + * Returns true if the provided object is an Object (i.e. not a string literal) + * and is either Iterable or Array-like. + * + * This may be used in place of [Array.isArray()][isArray] to determine if an + * object should be iterated-over. It always excludes string literals and + * includes Arrays (regardless of if it is Iterable). It also includes other + * Array-like objects such as NodeList, TypedArray, and Buffer. + * + * @example + * + * isCollection([ 1, 2, 3 ]) // true + * isCollection('ABC') // false + * isCollection({ length: 1, 0: 'Alpha' }) // true + * isCollection({ key: 'value' }) // false + * isCollection(new Map()) // true + * + * @param obj + * An Object value which might implement the Iterable or Array-like protocols. + * @return true if Iterable or Array-like Object. + */ export default function isCollection(obj: any): boolean; diff --git a/src/jsutils/isObjectLike.d.ts b/src/jsutils/isObjectLike.d.ts index 05e69785b3..2d974a7b17 100644 --- a/src/jsutils/isObjectLike.d.ts +++ b/src/jsutils/isObjectLike.d.ts @@ -1 +1,5 @@ +/** + * Return true if `value` is object-like. A value is object-like if it's not + * `null` and has a `typeof` result of "object". + */ export default function isObjectLike(value: any): boolean; diff --git a/src/jsutils/nodejsCustomInspectSymbol.d.ts b/src/jsutils/nodejsCustomInspectSymbol.d.ts index 84ee6f3770..6c22ea3b3d 100644 --- a/src/jsutils/nodejsCustomInspectSymbol.d.ts +++ b/src/jsutils/nodejsCustomInspectSymbol.d.ts @@ -1,4 +1,3 @@ -// istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) declare const nodejsCustomInspectSymbol: symbol | undefined; export default nodejsCustomInspectSymbol; diff --git a/src/jsutils/suggestionList.d.ts b/src/jsutils/suggestionList.d.ts index 560c1c5355..ce733ab833 100644 --- a/src/jsutils/suggestionList.d.ts +++ b/src/jsutils/suggestionList.d.ts @@ -1,3 +1,7 @@ +/** + * Given an invalid input string and a list of valid options, returns a filtered + * list of valid options sorted based on their similarity with the input. + */ export default function suggestionList( input: string, options: ReadonlyArray, diff --git a/src/jsutils/toObjMap.d.ts b/src/jsutils/toObjMap.d.ts index b17aecfaf5..a32b4c09b5 100644 --- a/src/jsutils/toObjMap.d.ts +++ b/src/jsutils/toObjMap.d.ts @@ -5,9 +5,7 @@ import { ReadOnlyObjMapLike, } from './ObjMap'; -// eslint-disable-next-line import/export -export default function toObjMap(obj: ObjMapLike): ObjMap; -// eslint-disable-next-line import/export -export default function toObjMap( - obj: ReadOnlyObjMapLike, -): ReadOnlyObjMap; +declare function toObjMap(obj: ObjMapLike): ObjMap; +declare function toObjMap(obj: ReadOnlyObjMapLike): ReadOnlyObjMap; + +export default toObjMap;