Skip to content

Commit 0252608

Browse files
committed
fix async iterable return type
from flow to ts conversion
1 parent 5f54a57 commit 0252608

12 files changed

+54
-80
lines changed

src/jsutils/isAsyncIterable.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
* Returns true if the provided object implements the AsyncIterator protocol via
33
* either implementing a `Symbol.asyncIterator` or `"@@asyncIterator"` method.
44
*/
5-
declare function isAsyncIterable(value: unknown): boolean; // FIXME: TS_CONVERTION %check
6-
7-
// eslint-disable-next-line no-redeclare
8-
export default function isAsyncIterable(maybeAsyncIterable) {
5+
export default function isAsyncIterable(maybeAsyncIterable:unknown): maybeAsyncIterable is AsyncIterable<unknown> {
96
if (maybeAsyncIterable == null || typeof maybeAsyncIterable !== 'object') {
107
return false;
118
}

src/jsutils/isCollection.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
* An Object value which might implement the Iterable or Array-like protocols.
2020
* @return {boolean} true if Iterable or Array-like Object.
2121
*/
22-
declare function isCollection(value: unknown): boolean; // FIXME: TS_CONVERTION %check
23-
24-
// eslint-disable-next-line no-redeclare
25-
export default function isCollection(obj) {
22+
export default function isCollection(obj: unknown): obj is object| Symbol {
2623
if (obj == null || typeof obj !== 'object') {
2724
return false;
2825
}

src/jsutils/isObjectLike.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
* Return true if `value` is object-like. A value is object-like if it's not
33
* `null` and has a `typeof` result of "object".
44
*/
5-
export default function isObjectLike(value: unknown): boolean { // FIXME: TS_CONVERTION %check
5+
export default function isObjectLike(value: unknown): value is object {
66
return typeof value == 'object' && value !== null;
77
}

src/jsutils/isPromise.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
* Returns true if the value acts like a Promise, i.e. has a "then" function,
33
* otherwise returns false.
44
*/
5-
declare function isPromise(value: unknown): boolean; // FIXME: TS_CONVERTION %check
6-
7-
// eslint-disable-next-line no-redeclare
8-
export default function isPromise(value) {
5+
export default function isPromise(value: unknown): value is Promise<unknown> {
96
return typeof value?.then === 'function';
107
}

src/language/ast.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class Token {
136136
/**
137137
* @internal
138138
*/
139-
export function isNode(maybeNode: unknown): boolean { // FIXME: TS_CONVERTION %check
139+
export function isNode(maybeNode: unknown): maybeNode is ASTNode {
140140
return maybeNode != null && typeof maybeNode.kind === 'string';
141141
}
142142

src/language/lexer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class Lexer {
7575
/**
7676
* @internal
7777
*/
78-
export function isPunctuatorTokenKind(kind: TokenKindEnum): boolean {
78+
export function isPunctuatorTokenKind(kind: TokenKindEnum): kind is typeof TokenKind {
7979
return (
8080
kind === TokenKind.BANG ||
8181
kind === TokenKind.DOLLAR ||

src/language/predicates.ts

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
1-
import type { ASTNode } from './ast';
1+
import {
2+
ASTNode,
3+
DefinitionNode,
4+
ExecutableDefinitionNode,
5+
SelectionNode,
6+
ValueNode,
7+
TypeNode,
8+
TypeSystemDefinitionNode,
9+
TypeDefinitionNode,
10+
TypeSystemExtensionNode,
11+
TypeExtensionNode,
12+
} from './ast';
213
import { Kind } from './kinds';
314

4-
export function isDefinitionNode(node: ASTNode): boolean {
15+
export function isDefinitionNode(node: ASTNode): node is DefinitionNode {
516
return (
617
isExecutableDefinitionNode(node) ||
718
isTypeSystemDefinitionNode(node) ||
819
isTypeSystemExtensionNode(node)
920
);
1021
}
1122

12-
export function isExecutableDefinitionNode(node: ASTNode): boolean {
23+
export function isExecutableDefinitionNode(node: ASTNode): node is ExecutableDefinitionNode {
1324
return (
1425
node.kind === Kind.OPERATION_DEFINITION ||
1526
node.kind === Kind.FRAGMENT_DEFINITION
1627
);
1728
}
1829

19-
export function isSelectionNode(node: ASTNode): boolean {
30+
export function isSelectionNode(node: ASTNode): node is SelectionNode {
2031
return (
2132
node.kind === Kind.FIELD ||
2233
node.kind === Kind.FRAGMENT_SPREAD ||
2334
node.kind === Kind.INLINE_FRAGMENT
2435
);
2536
}
2637

27-
export function isValueNode(node: ASTNode): boolean {
38+
export function isValueNode(node: ASTNode): node is ValueNode {
2839
return (
2940
node.kind === Kind.VARIABLE ||
3041
node.kind === Kind.INT ||
@@ -38,23 +49,23 @@ export function isValueNode(node: ASTNode): boolean {
3849
);
3950
}
4051

41-
export function isTypeNode(node: ASTNode): boolean {
52+
export function isTypeNode(node: ASTNode): node is TypeNode {
4253
return (
4354
node.kind === Kind.NAMED_TYPE ||
4455
node.kind === Kind.LIST_TYPE ||
4556
node.kind === Kind.NON_NULL_TYPE
4657
);
4758
}
4859

49-
export function isTypeSystemDefinitionNode(node: ASTNode): boolean {
60+
export function isTypeSystemDefinitionNode(node: ASTNode): node is TypeSystemDefinitionNode {
5061
return (
5162
node.kind === Kind.SCHEMA_DEFINITION ||
5263
isTypeDefinitionNode(node) ||
5364
node.kind === Kind.DIRECTIVE_DEFINITION
5465
);
5566
}
5667

57-
export function isTypeDefinitionNode(node: ASTNode): boolean {
68+
export function isTypeDefinitionNode(node: ASTNode): node is TypeDefinitionNode {
5869
return (
5970
node.kind === Kind.SCALAR_TYPE_DEFINITION ||
6071
node.kind === Kind.OBJECT_TYPE_DEFINITION ||
@@ -65,11 +76,11 @@ export function isTypeDefinitionNode(node: ASTNode): boolean {
6576
);
6677
}
6778

68-
export function isTypeSystemExtensionNode(node: ASTNode): boolean {
79+
export function isTypeSystemExtensionNode(node: ASTNode): node is TypeSystemExtensionNode {
6980
return node.kind === Kind.SCHEMA_EXTENSION || isTypeExtensionNode(node);
7081
}
7182

72-
export function isTypeExtensionNode(node: ASTNode): boolean {
83+
export function isTypeExtensionNode(node: ASTNode): node is TypeExtensionNode {
7384
return (
7485
node.kind === Kind.SCALAR_TYPE_EXTENSION ||
7586
node.kind === Kind.OBJECT_TYPE_EXTENSION ||

src/language/source.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ export class Source {
5353
*
5454
* @internal
5555
*/
56-
declare function isSource(source: unknown): boolean;
57-
// eslint-disable-next-line no-redeclare
58-
export function isSource(source) {
56+
export function isSource(source: unknown): source is Source {
5957
return instanceOf(source, Source);
6058
}

src/type/definition.ts

+23-43
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export type GraphQLType =
6565
| GraphQLList<any>
6666
| GraphQLNonNull<any>;
6767

68-
export function isType(type: unknown): boolean {
68+
export function isType(type: unknown): type is GraphQLType {
6969
return (
7070
isScalarType(type) ||
7171
isObjectType(type) ||
@@ -88,10 +88,7 @@ export function assertType(type: unknown): GraphQLType {
8888
/**
8989
* There are predicates for each kind of GraphQL type.
9090
*/
91-
92-
declare function isScalarType(type: unknown): boolean;
93-
// eslint-disable-next-line no-redeclare
94-
export function isScalarType(type) {
91+
export function isScalarType(type: unknown): type is GraphQLScalarType {
9592
return instanceOf(type, GraphQLScalarType);
9693
}
9794

@@ -102,9 +99,7 @@ export function assertScalarType(type: unknown): GraphQLScalarType {
10299
return type;
103100
}
104101

105-
declare function isObjectType(type: unknown): boolean;
106-
// eslint-disable-next-line no-redeclare
107-
export function isObjectType(type) {
102+
export function isObjectType(type: unknown): type is GraphQLObjectType {
108103
return instanceOf(type, GraphQLObjectType);
109104
}
110105

@@ -115,9 +110,7 @@ export function assertObjectType(type: unknown): GraphQLObjectType {
115110
return type;
116111
}
117112

118-
declare function isInterfaceType(type: unknown): boolean;
119-
// eslint-disable-next-line no-redeclare
120-
export function isInterfaceType(type) {
113+
export function isInterfaceType(type: unknown): type is GraphQLInterfaceType {
121114
return instanceOf(type, GraphQLInterfaceType);
122115
}
123116

@@ -130,9 +123,7 @@ export function assertInterfaceType(type: unknown): GraphQLInterfaceType {
130123
return type;
131124
}
132125

133-
declare function isUnionType(type: unknown): boolean;
134-
// eslint-disable-next-line no-redeclare
135-
export function isUnionType(type) {
126+
export function isUnionType(type: unknown): type is GraphQLUnionType {
136127
return instanceOf(type, GraphQLUnionType);
137128
}
138129

@@ -143,9 +134,7 @@ export function assertUnionType(type: unknown): GraphQLUnionType {
143134
return type;
144135
}
145136

146-
declare function isEnumType(type: unknown): boolean;
147-
// eslint-disable-next-line no-redeclare
148-
export function isEnumType(type) {
137+
export function isEnumType(type: unknown): type is GraphQLEnumType {
149138
return instanceOf(type, GraphQLEnumType);
150139
}
151140

@@ -156,9 +145,7 @@ export function assertEnumType(type: unknown): GraphQLEnumType {
156145
return type;
157146
}
158147

159-
declare function isInputObjectType(type: unknown): boolean;
160-
// eslint-disable-next-line no-redeclare
161-
export function isInputObjectType(type) {
148+
export function isInputObjectType(type: unknown): type is GraphQLInputObjectType {
162149
return instanceOf(type, GraphQLInputObjectType);
163150
}
164151

@@ -171,9 +158,7 @@ export function assertInputObjectType(type: unknown): GraphQLInputObjectType {
171158
return type;
172159
}
173160

174-
declare function isListType(type: unknown): boolean;
175-
// eslint-disable-next-line no-redeclare
176-
export function isListType(type) {
161+
export function isListType(type: unknown): type is GraphQLList<any> {
177162
return instanceOf(type, GraphQLList);
178163
}
179164

@@ -184,9 +169,7 @@ export function assertListType(type: unknown): GraphQLList<any> {
184169
return type;
185170
}
186171

187-
declare function isNonNullType(type: unknown): boolean;
188-
// eslint-disable-next-line no-redeclare
189-
export function isNonNullType(type) {
172+
export function isNonNullType(type: unknown): type is GraphQLNonNull<any> {
190173
return instanceOf(type, GraphQLNonNull);
191174
}
192175

@@ -212,7 +195,7 @@ export type GraphQLInputType =
212195
| GraphQLList<GraphQLInputType>,
213196
>;
214197

215-
export function isInputType(type: unknown): boolean {
198+
export function isInputType(type: unknown): type is GraphQLInputType {
216199
return (
217200
isScalarType(type) ||
218201
isEnumType(type) ||
@@ -247,7 +230,7 @@ export type GraphQLOutputType =
247230
| GraphQLList<GraphQLOutputType>,
248231
>;
249232

250-
export function isOutputType(type: unknown): boolean {
233+
export function isOutputType(type: unknown): type is GraphQLOutputType {
251234
return (
252235
isScalarType(type) ||
253236
isObjectType(type) ||
@@ -270,7 +253,7 @@ export function assertOutputType(type: unknown): GraphQLOutputType {
270253
*/
271254
export type GraphQLLeafType = GraphQLScalarType | GraphQLEnumType;
272255

273-
export function isLeafType(type: unknown): boolean {
256+
export function isLeafType(type: unknown): type is GraphQLLeafType {
274257
return isScalarType(type) || isEnumType(type);
275258
}
276259

@@ -289,7 +272,7 @@ export type GraphQLCompositeType =
289272
| GraphQLInterfaceType
290273
| GraphQLUnionType;
291274

292-
export function isCompositeType(type: unknown): boolean {
275+
export function isCompositeType(type: unknown): type is GraphQLCompositeType {
293276
return isObjectType(type) || isInterfaceType(type) || isUnionType(type);
294277
}
295278

@@ -307,7 +290,7 @@ export function assertCompositeType(type: unknown): GraphQLCompositeType {
307290
*/
308291
export type GraphQLAbstractType = GraphQLInterfaceType | GraphQLUnionType;
309292

310-
export function isAbstractType(type: unknown): boolean {
293+
export function isAbstractType(type: unknown): type is GraphQLAbstractType {
311294
return isInterfaceType(type) || isUnionType(type);
312295
}
313296

@@ -414,7 +397,7 @@ export class GraphQLNonNull<T extends GraphQLNullableType> {
414397

415398
export type GraphQLWrappingType = GraphQLList<any> | GraphQLNonNull<any>;
416399

417-
export function isWrappingType(type: unknown): boolean {
400+
export function isWrappingType(type: unknown): type is GraphQLWrappingType {
418401
return isListType(type) || isNonNullType(type);
419402
}
420403

@@ -437,7 +420,7 @@ export type GraphQLNullableType =
437420
| GraphQLInputObjectType
438421
| GraphQLList<any>;
439422

440-
export function isNullableType(type: unknown): boolean {
423+
export function isNullableType(type: unknown): type is GraphQLNullableType {
441424
return isType(type) && !isNonNullType(type);
442425
}
443426

@@ -448,12 +431,11 @@ export function assertNullableType(type: unknown): GraphQLNullableType {
448431
return type;
449432
}
450433

451-
/* eslint-disable no-redeclare */
452-
declare function getNullableType(type: void | null): void;
453-
declare function getNullableType<T extends GraphQLNullableType>(type: T): T;
454-
declare function getNullableType<T>(type: GraphQLNonNull<T>): T;
434+
435+
export function getNullableType(type: void | null): void;
436+
export function getNullableType<T extends GraphQLNullableType>(type: T): T;
437+
export function getNullableType<T extends GraphQLNullableType>(type: GraphQLNonNull<T>): T;
455438
export function getNullableType(type) {
456-
/* eslint-enable no-redeclare */
457439
if (type) {
458440
return isNonNullType(type) ? type.ofType : type;
459441
}
@@ -470,7 +452,7 @@ export type GraphQLNamedType =
470452
| GraphQLEnumType
471453
| GraphQLInputObjectType;
472454

473-
export function isNamedType(type: unknown): boolean {
455+
export function isNamedType(type: unknown): type is GraphQLNamedType {
474456
return (
475457
isScalarType(type) ||
476458
isObjectType(type) ||
@@ -488,11 +470,9 @@ export function assertNamedType(type: unknown): GraphQLNamedType {
488470
return type;
489471
}
490472

491-
/* eslint-disable no-redeclare */
492-
declare function getNamedType(type: void | null): void;
493-
declare function getNamedType(type: GraphQLType): GraphQLNamedType;
473+
export function getNamedType(type: void | null): void;
474+
export function getNamedType(type: GraphQLType): GraphQLNamedType;
494475
export function getNamedType(type) {
495-
/* eslint-enable no-redeclare */
496476
if (type) {
497477
let unwrappedType = type;
498478
while (isWrappingType(unwrappedType)) {

src/type/directives.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ import { Maybe } from '../jsutils/Maybe';
2222
/**
2323
* Test if the given value is a GraphQL directive.
2424
*/
25-
declare function isDirective(
26-
directive: unknown,
27-
): boolean;
28-
// eslint-disable-next-line no-redeclare
29-
export function isDirective(directive) {
25+
export function isDirective(directive: unknown): directive is GraphQLDirective {
3026
return instanceOf(directive, GraphQLDirective);
3127
}
3228

src/type/introspection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,6 @@ export const introspectionTypes = Object.freeze([
541541
__TypeKind,
542542
]);
543543

544-
export function isIntrospectionType(type: GraphQLNamedType): boolean { // FIXME: TS_CONVERTION %check
544+
export function isIntrospectionType(type: GraphQLNamedType): boolean {
545545
return introspectionTypes.some(({ name }) => type.name === name);
546546
}

src/type/schema.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ import { Maybe } from '../jsutils/Maybe';
4343
/**
4444
* Test if the given value is a GraphQL schema.
4545
*/
46-
declare function isSchema(schema: unknown): boolean;
47-
// eslint-disable-next-line no-redeclare
48-
export function isSchema(schema) {
46+
export function isSchema(schema: unknown): schema is GraphQLSchema {
4947
return instanceOf(schema, GraphQLSchema);
5048
}
5149

0 commit comments

Comments
 (0)