Skip to content

Commit 86523ec

Browse files
Flow: Replace force type conversion with explicit $FlowFixMe comments (#3081)
In preparation for TS convertion
1 parent 0bb8500 commit 86523ec

16 files changed

+178
-135
lines changed

src/error/GraphQLError.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ export class GraphQLError extends Error {
133133
}
134134
}
135135

136-
Object.defineProperties((this: any), {
136+
// $FlowFixMe[cannot-write] FIXME
137+
Object.defineProperties(this, {
137138
name: { value: 'GraphQLError' },
138139
message: {
139140
value: message,

src/error/__tests__/locatedError-test.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,26 @@ describe('locatedError', () => {
1717
});
1818

1919
it('passes GraphQLError-ish through', () => {
20-
const e = new Error('I have a different prototype chain');
21-
(e: any).locations = [];
22-
(e: any).path = [];
23-
(e: any).nodes = [];
24-
(e: any).source = null;
25-
(e: any).positions = [];
26-
(e: any).name = 'GraphQLError';
20+
const e = new Error();
21+
// $FlowExpectedError[prop-missing]
22+
e.locations = [];
23+
// $FlowExpectedError[prop-missing]
24+
e.path = [];
25+
// $FlowExpectedError[prop-missing]
26+
e.nodes = [];
27+
// $FlowExpectedError[prop-missing]
28+
e.source = null;
29+
// $FlowExpectedError[prop-missing]
30+
e.positions = [];
31+
e.name = 'GraphQLError';
2732

2833
expect(locatedError(e, [], [])).to.deep.equal(e);
2934
});
3035

3136
it('does not pass through elasticsearch-like errors', () => {
3237
const e = new Error('I am from elasticsearch');
33-
(e: any).path = '/something/feed/_search';
38+
// $FlowExpectedError[prop-missing]
39+
e.path = '/something/feed/_search';
3440

3541
expect(locatedError(e, [], [])).to.not.deep.equal(e);
3642
});

src/error/locatedError.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ export function locatedError(
2222

2323
// Note: this uses a brand-check to support GraphQL errors originating from other contexts.
2424
if (Array.isArray(originalError.path)) {
25-
return (originalError: any);
25+
// $FlowExpectedError[incompatible-return]
26+
return originalError;
2627
}
2728

2829
return new GraphQLError(
2930
originalError.message,
30-
(originalError: any).nodes ?? nodes,
31-
(originalError: any).source,
32-
(originalError: any).positions,
31+
// $FlowFixMe[prop-missing] FIXME
32+
originalError.nodes ?? nodes,
33+
// $FlowFixMe[prop-missing] FIXME
34+
originalError.source,
35+
// $FlowFixMe[prop-missing] FIXME
36+
originalError.positions,
3337
path,
3438
originalError,
3539
);

src/execution/__tests__/abstract-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { parse } from '../../language/parser';
66
import { GraphQLSchema } from '../../type/schema';
77
import { GraphQLString, GraphQLBoolean } from '../../type/scalars';
88
import {
9+
assertInterfaceType,
910
GraphQLList,
1011
GraphQLObjectType,
1112
GraphQLInterfaceType,
@@ -569,13 +570,16 @@ describe('Execute: Handles execution of abstract types', () => {
569570
);
570571

571572
// FIXME: workaround since we can't inject resolveType into SDL
572-
(schema.getType('Pet'): any).resolveType = () => [];
573+
// $FlowExpectedError[incompatible-type]
574+
assertInterfaceType(schema.getType('Pet')).resolveType = () => [];
573575
expectError({ forTypeName: undefined }).toEqual(
574576
'Abstract type "Pet" must resolve to an Object type at runtime for field "Query.pet" with value { __typename: undefined }, received "[]".',
575577
);
576578

577579
// FIXME: workaround since we can't inject resolveType into SDL
578-
(schema.getType('Pet'): any).resolveType = () => schema.getType('Cat');
580+
assertInterfaceType(schema.getType('Pet')).resolveType =
581+
// $FlowExpectedError[incompatible-type]
582+
() => schema.getType('Cat');
579583
expectError({ forTypeName: undefined }).toEqual(
580584
'Support for returning GraphQLObjectType from resolveType was removed in [email protected] please return type name instead.',
581585
);

src/execution/__tests__/executor-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ describe('Execute: Handles basic execution tasks', () => {
489489
},
490490
asyncReturnErrorWithExtensions() {
491491
const error = new Error('Error getting asyncReturnErrorWithExtensions');
492-
(error: any).extensions = { foo: 'bar' };
492+
// $FlowExpectedError[prop-missing]
493+
error.extensions = { foo: 'bar' };
493494

494495
return Promise.resolve(error);
495496
},

src/jsutils/__tests__/inspect-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ describe('inspect', () => {
165165

166166
expect(inspect([[new Foo()]])).to.equal('[[[Foo]]]');
167167

168-
(Foo.prototype: any)[Symbol.toStringTag] = 'Bar';
168+
// $FlowExpectedError[prop-missing]
169+
Foo.prototype[Symbol.toStringTag] = 'Bar';
169170
expect(inspect([[new Foo()]])).to.equal('[[[Bar]]]');
170171

171172
// eslint-disable-next-line func-names

src/language/__tests__/predicates-test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ import {
1717
isTypeExtensionNode,
1818
} from '../predicates';
1919

20-
const allASTNodes: Array<ASTNode> = Object.values(Kind).map(
21-
(kind) => ({ kind }: any),
22-
);
23-
24-
function filterNodes(predicate: (node: ASTNode) => boolean): Array<string> {
25-
return allASTNodes.filter(predicate).map(({ kind }) => kind);
20+
function filterNodes(predicate: (ASTNode) => boolean): Array<string> {
21+
return Object.values(Kind).filter(
22+
// $FlowExpectedError[speculation-ambiguous] create node only with kind
23+
(kind) => predicate({ kind }),
24+
);
2625
}
2726

2827
describe('AST node predicates', () => {

src/language/lexer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export class Lexer {
6464
let token = this.token;
6565
if (token.kind !== TokenKind.EOF) {
6666
do {
67-
// Note: next is only mutable during parsing, so we cast to allow this.
68-
token = token.next ?? ((token: any).next = readToken(this, token));
67+
// $FlowFixMe[cannot-write] next is only mutable during parsing, so we cast to allow this.
68+
token = token.next ?? (token.next = readToken(this, token));
6969
} while (token.kind === TokenKind.COMMENT);
7070
}
7171
return token;

src/language/parser.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ export class Parser {
184184
const token = this.expectToken(TokenKind.NAME);
185185
return this.node(token, {
186186
kind: Kind.NAME,
187-
value: ((token.value: any): string),
187+
// $FlowFixMe[incompatible-return] FIXME
188+
value: token.value,
188189
});
189190
}
190191

@@ -413,7 +414,8 @@ export class Parser {
413414
}
414415

415416
parseConstArgument(): ConstArgumentNode {
416-
return (this.parseArgument(true): any);
417+
// $FlowFixMe[incompatible-return] FIXME during TS conversion
418+
return this.parseArgument(true);
417419
}
418420

419421
// Implements the parsing rules in the Fragments section.
@@ -517,13 +519,15 @@ export class Parser {
517519
this._lexer.advance();
518520
return this.node(token, {
519521
kind: Kind.INT,
520-
value: ((token.value: any): string),
522+
// $FlowFixMe[incompatible-return] FIXME
523+
value: token.value,
521524
});
522525
case TokenKind.FLOAT:
523526
this._lexer.advance();
524527
return this.node(token, {
525528
kind: Kind.FLOAT,
526-
value: ((token.value: any): string),
529+
// $FlowFixMe[incompatible-return] FIXME
530+
value: token.value,
527531
});
528532
case TokenKind.STRING:
529533
case TokenKind.BLOCK_STRING:
@@ -540,7 +544,8 @@ export class Parser {
540544
default:
541545
return this.node(token, {
542546
kind: Kind.ENUM,
543-
value: ((token.value: any): string),
547+
// $FlowFixMe[incompatible-return] FIXME
548+
value: token.value,
544549
});
545550
}
546551
case TokenKind.DOLLAR:
@@ -563,15 +568,17 @@ export class Parser {
563568
}
564569

565570
parseConstValueLiteral(): ConstValueNode {
566-
return (this.parseValueLiteral(true): any);
571+
// $FlowFixMe[incompatible-return] FIXME during TS conversion
572+
return this.parseValueLiteral(true);
567573
}
568574

569575
parseStringLiteral(): StringValueNode {
570576
const token = this._lexer.token;
571577
this._lexer.advance();
572578
return this.node(token, {
573579
kind: Kind.STRING,
574-
value: ((token.value: any): string),
580+
// $FlowFixMe[incompatible-return] FIXME
581+
value: token.value,
575582
block: token.kind === TokenKind.BLOCK_STRING,
576583
});
577584
}
@@ -631,7 +638,8 @@ export class Parser {
631638
}
632639

633640
parseConstDirectives(): Array<ConstDirectiveNode> {
634-
return (this.parseDirectives(true): any);
641+
// $FlowFixMe[incompatible-return] FIXME during TS conversion
642+
return this.parseDirectives(true);
635643
}
636644

637645
/**

0 commit comments

Comments
 (0)