diff --git a/src/jsutils/isAsyncIterable.ts b/src/jsutils/isAsyncIterable.ts index 5664996ad85..608230e7777 100644 --- a/src/jsutils/isAsyncIterable.ts +++ b/src/jsutils/isAsyncIterable.ts @@ -2,10 +2,7 @@ * Returns true if the provided object implements the AsyncIterator protocol via * either implementing a `Symbol.asyncIterator` or `"@@asyncIterator"` method. */ -declare function isAsyncIterable(value: unknown): boolean; // FIXME: TS_CONVERTION %check - -// eslint-disable-next-line no-redeclare -export default function isAsyncIterable(maybeAsyncIterable) { +export default function isAsyncIterable(maybeAsyncIterable:unknown): maybeAsyncIterable is AsyncIterable { if (maybeAsyncIterable == null || typeof maybeAsyncIterable !== 'object') { return false; } diff --git a/src/jsutils/isCollection.ts b/src/jsutils/isCollection.ts index d6df99eb661..1b8695b0b85 100644 --- a/src/jsutils/isCollection.ts +++ b/src/jsutils/isCollection.ts @@ -19,10 +19,7 @@ * An Object value which might implement the Iterable or Array-like protocols. * @return {boolean} true if Iterable or Array-like Object. */ -declare function isCollection(value: unknown): boolean; // FIXME: TS_CONVERTION %check - -// eslint-disable-next-line no-redeclare -export default function isCollection(obj) { +export default function isCollection(obj: unknown): obj is object| Symbol { if (obj == null || typeof obj !== 'object') { return false; } diff --git a/src/jsutils/isObjectLike.ts b/src/jsutils/isObjectLike.ts index 35486c50c71..9331c48f3e1 100644 --- a/src/jsutils/isObjectLike.ts +++ b/src/jsutils/isObjectLike.ts @@ -2,6 +2,6 @@ * 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: unknown): boolean { // FIXME: TS_CONVERTION %check +export default function isObjectLike(value: unknown): value is object { return typeof value == 'object' && value !== null; } diff --git a/src/jsutils/isPromise.ts b/src/jsutils/isPromise.ts index e44d20f19de..36a0eaef417 100644 --- a/src/jsutils/isPromise.ts +++ b/src/jsutils/isPromise.ts @@ -2,9 +2,6 @@ * Returns true if the value acts like a Promise, i.e. has a "then" function, * otherwise returns false. */ -declare function isPromise(value: unknown): boolean; // FIXME: TS_CONVERTION %check - -// eslint-disable-next-line no-redeclare -export default function isPromise(value) { +export default function isPromise(value: unknown): value is Promise { return typeof value?.then === 'function'; } diff --git a/src/language/ast.ts b/src/language/ast.ts index 8b8cba9a298..b4edb66c3b4 100644 --- a/src/language/ast.ts +++ b/src/language/ast.ts @@ -136,7 +136,7 @@ export class Token { /** * @internal */ -export function isNode(maybeNode: unknown): boolean { // FIXME: TS_CONVERTION %check +export function isNode(maybeNode: unknown): maybeNode is ASTNode { return maybeNode != null && typeof maybeNode.kind === 'string'; } diff --git a/src/language/lexer.ts b/src/language/lexer.ts index b39818d3f25..1204e6e0485 100644 --- a/src/language/lexer.ts +++ b/src/language/lexer.ts @@ -75,7 +75,7 @@ export class Lexer { /** * @internal */ -export function isPunctuatorTokenKind(kind: TokenKindEnum): boolean { +export function isPunctuatorTokenKind(kind: TokenKindEnum): kind is typeof TokenKind { return ( kind === TokenKind.BANG || kind === TokenKind.DOLLAR || diff --git a/src/language/predicates.ts b/src/language/predicates.ts index 5ca81a36517..a85c4745814 100644 --- a/src/language/predicates.ts +++ b/src/language/predicates.ts @@ -1,7 +1,18 @@ -import type { ASTNode } from './ast'; +import { + ASTNode, + DefinitionNode, + ExecutableDefinitionNode, + SelectionNode, + ValueNode, + TypeNode, + TypeSystemDefinitionNode, + TypeDefinitionNode, + TypeSystemExtensionNode, + TypeExtensionNode, +} from './ast'; import { Kind } from './kinds'; -export function isDefinitionNode(node: ASTNode): boolean { +export function isDefinitionNode(node: ASTNode): node is DefinitionNode { return ( isExecutableDefinitionNode(node) || isTypeSystemDefinitionNode(node) || @@ -9,14 +20,14 @@ export function isDefinitionNode(node: ASTNode): boolean { ); } -export function isExecutableDefinitionNode(node: ASTNode): boolean { +export function isExecutableDefinitionNode(node: ASTNode): node is ExecutableDefinitionNode { return ( node.kind === Kind.OPERATION_DEFINITION || node.kind === Kind.FRAGMENT_DEFINITION ); } -export function isSelectionNode(node: ASTNode): boolean { +export function isSelectionNode(node: ASTNode): node is SelectionNode { return ( node.kind === Kind.FIELD || node.kind === Kind.FRAGMENT_SPREAD || @@ -24,7 +35,7 @@ export function isSelectionNode(node: ASTNode): boolean { ); } -export function isValueNode(node: ASTNode): boolean { +export function isValueNode(node: ASTNode): node is ValueNode { return ( node.kind === Kind.VARIABLE || node.kind === Kind.INT || @@ -38,7 +49,7 @@ export function isValueNode(node: ASTNode): boolean { ); } -export function isTypeNode(node: ASTNode): boolean { +export function isTypeNode(node: ASTNode): node is TypeNode { return ( node.kind === Kind.NAMED_TYPE || node.kind === Kind.LIST_TYPE || @@ -46,7 +57,7 @@ export function isTypeNode(node: ASTNode): boolean { ); } -export function isTypeSystemDefinitionNode(node: ASTNode): boolean { +export function isTypeSystemDefinitionNode(node: ASTNode): node is TypeSystemDefinitionNode { return ( node.kind === Kind.SCHEMA_DEFINITION || isTypeDefinitionNode(node) || @@ -54,7 +65,7 @@ export function isTypeSystemDefinitionNode(node: ASTNode): boolean { ); } -export function isTypeDefinitionNode(node: ASTNode): boolean { +export function isTypeDefinitionNode(node: ASTNode): node is TypeDefinitionNode { return ( node.kind === Kind.SCALAR_TYPE_DEFINITION || node.kind === Kind.OBJECT_TYPE_DEFINITION || @@ -65,11 +76,11 @@ export function isTypeDefinitionNode(node: ASTNode): boolean { ); } -export function isTypeSystemExtensionNode(node: ASTNode): boolean { +export function isTypeSystemExtensionNode(node: ASTNode): node is TypeSystemExtensionNode { return node.kind === Kind.SCHEMA_EXTENSION || isTypeExtensionNode(node); } -export function isTypeExtensionNode(node: ASTNode): boolean { +export function isTypeExtensionNode(node: ASTNode): node is TypeExtensionNode { return ( node.kind === Kind.SCALAR_TYPE_EXTENSION || node.kind === Kind.OBJECT_TYPE_EXTENSION || diff --git a/src/language/source.ts b/src/language/source.ts index e737bf7ec8c..ea665f2692d 100644 --- a/src/language/source.ts +++ b/src/language/source.ts @@ -53,8 +53,6 @@ export class Source { * * @internal */ -declare function isSource(source: unknown): boolean; -// eslint-disable-next-line no-redeclare -export function isSource(source) { +export function isSource(source: unknown): source is Source { return instanceOf(source, Source); } diff --git a/src/type/definition.ts b/src/type/definition.ts index 5a38dc6396c..d3da0ae21b6 100644 --- a/src/type/definition.ts +++ b/src/type/definition.ts @@ -65,7 +65,7 @@ export type GraphQLType = | GraphQLList | GraphQLNonNull; -export function isType(type: unknown): boolean { +export function isType(type: unknown): type is GraphQLType { return ( isScalarType(type) || isObjectType(type) || @@ -88,10 +88,7 @@ export function assertType(type: unknown): GraphQLType { /** * There are predicates for each kind of GraphQL type. */ - -declare function isScalarType(type: unknown): boolean; -// eslint-disable-next-line no-redeclare -export function isScalarType(type) { +export function isScalarType(type: unknown): type is GraphQLScalarType { return instanceOf(type, GraphQLScalarType); } @@ -102,9 +99,7 @@ export function assertScalarType(type: unknown): GraphQLScalarType { return type; } -declare function isObjectType(type: unknown): boolean; -// eslint-disable-next-line no-redeclare -export function isObjectType(type) { +export function isObjectType(type: unknown): type is GraphQLObjectType { return instanceOf(type, GraphQLObjectType); } @@ -115,9 +110,7 @@ export function assertObjectType(type: unknown): GraphQLObjectType { return type; } -declare function isInterfaceType(type: unknown): boolean; -// eslint-disable-next-line no-redeclare -export function isInterfaceType(type) { +export function isInterfaceType(type: unknown): type is GraphQLInterfaceType { return instanceOf(type, GraphQLInterfaceType); } @@ -130,9 +123,7 @@ export function assertInterfaceType(type: unknown): GraphQLInterfaceType { return type; } -declare function isUnionType(type: unknown): boolean; -// eslint-disable-next-line no-redeclare -export function isUnionType(type) { +export function isUnionType(type: unknown): type is GraphQLUnionType { return instanceOf(type, GraphQLUnionType); } @@ -143,9 +134,7 @@ export function assertUnionType(type: unknown): GraphQLUnionType { return type; } -declare function isEnumType(type: unknown): boolean; -// eslint-disable-next-line no-redeclare -export function isEnumType(type) { +export function isEnumType(type: unknown): type is GraphQLEnumType { return instanceOf(type, GraphQLEnumType); } @@ -156,9 +145,7 @@ export function assertEnumType(type: unknown): GraphQLEnumType { return type; } -declare function isInputObjectType(type: unknown): boolean; -// eslint-disable-next-line no-redeclare -export function isInputObjectType(type) { +export function isInputObjectType(type: unknown): type is GraphQLInputObjectType { return instanceOf(type, GraphQLInputObjectType); } @@ -171,9 +158,7 @@ export function assertInputObjectType(type: unknown): GraphQLInputObjectType { return type; } -declare function isListType(type: unknown): boolean; -// eslint-disable-next-line no-redeclare -export function isListType(type) { +export function isListType(type: unknown): type is GraphQLList { return instanceOf(type, GraphQLList); } @@ -184,9 +169,7 @@ export function assertListType(type: unknown): GraphQLList { return type; } -declare function isNonNullType(type: unknown): boolean; -// eslint-disable-next-line no-redeclare -export function isNonNullType(type) { +export function isNonNullType(type: unknown): type is GraphQLNonNull { return instanceOf(type, GraphQLNonNull); } @@ -212,7 +195,7 @@ export type GraphQLInputType = | GraphQLList, >; -export function isInputType(type: unknown): boolean { +export function isInputType(type: unknown): type is GraphQLInputType { return ( isScalarType(type) || isEnumType(type) || @@ -247,7 +230,7 @@ export type GraphQLOutputType = | GraphQLList, >; -export function isOutputType(type: unknown): boolean { +export function isOutputType(type: unknown): type is GraphQLOutputType { return ( isScalarType(type) || isObjectType(type) || @@ -270,7 +253,7 @@ export function assertOutputType(type: unknown): GraphQLOutputType { */ export type GraphQLLeafType = GraphQLScalarType | GraphQLEnumType; -export function isLeafType(type: unknown): boolean { +export function isLeafType(type: unknown): type is GraphQLLeafType { return isScalarType(type) || isEnumType(type); } @@ -289,7 +272,7 @@ export type GraphQLCompositeType = | GraphQLInterfaceType | GraphQLUnionType; -export function isCompositeType(type: unknown): boolean { +export function isCompositeType(type: unknown): type is GraphQLCompositeType { return isObjectType(type) || isInterfaceType(type) || isUnionType(type); } @@ -307,7 +290,7 @@ export function assertCompositeType(type: unknown): GraphQLCompositeType { */ export type GraphQLAbstractType = GraphQLInterfaceType | GraphQLUnionType; -export function isAbstractType(type: unknown): boolean { +export function isAbstractType(type: unknown): type is GraphQLAbstractType { return isInterfaceType(type) || isUnionType(type); } @@ -414,7 +397,7 @@ export class GraphQLNonNull { export type GraphQLWrappingType = GraphQLList | GraphQLNonNull; -export function isWrappingType(type: unknown): boolean { +export function isWrappingType(type: unknown): type is GraphQLWrappingType { return isListType(type) || isNonNullType(type); } @@ -437,7 +420,7 @@ export type GraphQLNullableType = | GraphQLInputObjectType | GraphQLList; -export function isNullableType(type: unknown): boolean { +export function isNullableType(type: unknown): type is GraphQLNullableType { return isType(type) && !isNonNullType(type); } @@ -448,12 +431,11 @@ export function assertNullableType(type: unknown): GraphQLNullableType { return type; } -/* eslint-disable no-redeclare */ -declare function getNullableType(type: void | null): void; -declare function getNullableType(type: T): T; -declare function getNullableType(type: GraphQLNonNull): T; + +export function getNullableType(type: void | null): void; +export function getNullableType(type: T): T; +export function getNullableType(type: GraphQLNonNull): T; export function getNullableType(type) { - /* eslint-enable no-redeclare */ if (type) { return isNonNullType(type) ? type.ofType : type; } @@ -470,7 +452,7 @@ export type GraphQLNamedType = | GraphQLEnumType | GraphQLInputObjectType; -export function isNamedType(type: unknown): boolean { +export function isNamedType(type: unknown): type is GraphQLNamedType { return ( isScalarType(type) || isObjectType(type) || @@ -488,11 +470,9 @@ export function assertNamedType(type: unknown): GraphQLNamedType { return type; } -/* eslint-disable no-redeclare */ -declare function getNamedType(type: void | null): void; -declare function getNamedType(type: GraphQLType): GraphQLNamedType; +export function getNamedType(type: void | null): void; +export function getNamedType(type: GraphQLType): GraphQLNamedType; export function getNamedType(type) { - /* eslint-enable no-redeclare */ if (type) { let unwrappedType = type; while (isWrappingType(unwrappedType)) { diff --git a/src/type/directives.ts b/src/type/directives.ts index 9bc3659f000..dbdcb6b52af 100644 --- a/src/type/directives.ts +++ b/src/type/directives.ts @@ -22,11 +22,7 @@ import { Maybe } from '../jsutils/Maybe'; /** * Test if the given value is a GraphQL directive. */ -declare function isDirective( - directive: unknown, -): boolean; -// eslint-disable-next-line no-redeclare -export function isDirective(directive) { +export function isDirective(directive: unknown): directive is GraphQLDirective { return instanceOf(directive, GraphQLDirective); } diff --git a/src/type/introspection.ts b/src/type/introspection.ts index 0d9b0e2d815..f7aedf17045 100644 --- a/src/type/introspection.ts +++ b/src/type/introspection.ts @@ -541,6 +541,6 @@ export const introspectionTypes = Object.freeze([ __TypeKind, ]); -export function isIntrospectionType(type: GraphQLNamedType): boolean { // FIXME: TS_CONVERTION %check +export function isIntrospectionType(type: GraphQLNamedType): boolean { return introspectionTypes.some(({ name }) => type.name === name); } diff --git a/src/type/schema.ts b/src/type/schema.ts index 299db414612..7e64aa86fd6 100644 --- a/src/type/schema.ts +++ b/src/type/schema.ts @@ -43,9 +43,7 @@ import { Maybe } from '../jsutils/Maybe'; /** * Test if the given value is a GraphQL schema. */ -declare function isSchema(schema: unknown): boolean; -// eslint-disable-next-line no-redeclare -export function isSchema(schema) { +export function isSchema(schema: unknown): schema is GraphQLSchema { return instanceOf(schema, GraphQLSchema); }