diff --git a/src/__fixtures__/index.d.ts b/src/__fixtures__/index.d.ts new file mode 100644 index 0000000000..b51118abf7 --- /dev/null +++ b/src/__fixtures__/index.d.ts @@ -0,0 +1,4 @@ +export declare const bigSchemaSDL: string; +export declare const bigSchemaIntrospectionResult: { data: unknown }; +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..299f5af5e3 --- /dev/null +++ b/src/jsutils/didYouMean.d.ts @@ -0,0 +1,10 @@ +/** + * 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 new file mode 100644 index 0000000000..af766f2dbb --- /dev/null +++ b/src/jsutils/identityFunc.d.ts @@ -0,0 +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 new file mode 100644 index 0000000000..76970a8ffb --- /dev/null +++ b/src/jsutils/inspect.d.ts @@ -0,0 +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 new file mode 100644 index 0000000000..c80c7c74cd --- /dev/null +++ b/src/jsutils/instanceOf.d.ts @@ -0,0 +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/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..ee1a5d184c --- /dev/null +++ b/src/jsutils/isCollection.d.ts @@ -0,0 +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 new file mode 100644 index 0000000000..2d974a7b17 --- /dev/null +++ b/src/jsutils/isObjectLike.d.ts @@ -0,0 +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 new file mode 100644 index 0000000000..6c22ea3b3d --- /dev/null +++ b/src/jsutils/nodejsCustomInspectSymbol.d.ts @@ -0,0 +1,3 @@ +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..ce733ab833 --- /dev/null +++ b/src/jsutils/suggestionList.d.ts @@ -0,0 +1,8 @@ +/** + * 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, +): Array; diff --git a/src/jsutils/toObjMap.d.ts b/src/jsutils/toObjMap.d.ts new file mode 100644 index 0000000000..a32b4c09b5 --- /dev/null +++ b/src/jsutils/toObjMap.d.ts @@ -0,0 +1,11 @@ +import { + ObjMap, + ObjMapLike, + ReadOnlyObjMap, + ReadOnlyObjMapLike, +} from './ObjMap'; + +declare function toObjMap(obj: ObjMapLike): ObjMap; +declare function toObjMap(obj: ReadOnlyObjMapLike): ReadOnlyObjMap; + +export default toObjMap;