Skip to content

Commit baa6a5d

Browse files
committed
Fix TSC errors
1 parent f6655ec commit baa6a5d

33 files changed

+99
-47
lines changed

src/error/GraphQLError.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ export class GraphQLError extends Error {
9898
_source = _nodes[0].loc?.source;
9999
}
100100

101-
let _positions = positions;
102-
if (!_positions && _nodes) {
101+
let _positions;
102+
if (positions) {
103+
_positions = positions;
104+
} else if (_nodes) {
103105
_positions = [];
104106
for (const node of _nodes) {
105107
if (node.loc) {

src/error/locatedError.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function locatedError(
2222
: new Error('Unexpected error value: ' + inspect(rawOriginalError));
2323

2424
// Note: this uses a brand-check to support GraphQL errors originating from other contexts.
25+
// @ts-expect-error FIXME: TS Conversion
2526
if (Array.isArray(originalError.path)) {
2627
// @ts-expect-error
2728
return originalError;

src/execution/execute.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
191191
// field and its descendants will be omitted, and sibling fields will still
192192
// be executed. An execution which encounters errors will still result in a
193193
// resolved Promise.
194+
// @ts-expect-error FIXME: TS Conversion
194195
const data = executeOperation(exeContext, exeContext.operation, rootValue);
196+
// @ts-expect-error FIXME: TS Conversion
195197
return buildResponse(exeContext, data);
196198
}
197199

@@ -313,7 +315,6 @@ export function buildExecutionContext(
313315
return coercedVariableValues.errors;
314316
}
315317

316-
// @ts-expect-error
317318
return {
318319
schema,
319320
fragments,
@@ -1078,7 +1079,7 @@ function _collectSubfields(
10781079
fieldNodes: ReadonlyArray<FieldNode>,
10791080
): Map<string, Array<FieldNode>> {
10801081
let subFieldNodes = new Map();
1081-
const visitedFragmentNames = new Set();
1082+
const visitedFragmentNames = new Set<string>();
10821083
for (const node of fieldNodes) {
10831084
if (node.selectionSet) {
10841085
subFieldNodes = collectFields(

src/jsutils/__tests__/inspect-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('inspect', () => {
124124
});
125125

126126
it('detect circular objects', () => {
127-
const obj = {};
127+
const obj: { [name: string]: unknown } = {};
128128
obj.self = obj;
129129
obj.deepSelf = { self: obj };
130130

src/jsutils/__tests__/isIterableObject-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('isIterableObject', () => {
6060
};
6161
expect(isIterableObject(invalidIterable)).to.equal(false);
6262

63-
const arrayLike = {};
63+
const arrayLike: { [key: string]: unknown } = {};
6464
arrayLike[0] = 'Alpha';
6565
arrayLike[1] = 'Bravo';
6666
arrayLike[2] = 'Charlie';

src/jsutils/inspect.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ function formatObjectValue(
3535

3636
const seenValues = [...previouslySeenValues, value];
3737

38+
// @ts-expect-error FIXME: TS Conversion
3839
if (typeof value.toJSON === 'function') {
40+
// @ts-expect-error FIXME: TS Conversion
3941
const jsonValue = (value.toJSON as () => unknown)();
4042

4143
// check for infinite recursion

src/jsutils/isPromise.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
* otherwise returns false.
44
*/
55
export function isPromise(value: unknown): value is Promise<unknown> {
6-
return typeof value?.then === 'function';
6+
// eslint-disable-next-line @typescript-eslint/dot-notation
7+
return typeof value?.['then'] === 'function';
78
}

src/language/__tests__/printer-test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { print } from '../printer';
99

1010
describe('Printer: Query document', () => {
1111
it('prints minimal ast', () => {
12-
const ast = { kind: 'Field', name: { kind: 'Name', value: 'foo' } };
12+
const ast = {
13+
kind: 'Field',
14+
name: { kind: 'Name', value: 'foo' },
15+
} as const;
1316
expect(print(ast)).to.equal('foo');
1417
});
1518

src/language/__tests__/schema-printer-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Printer: SDL document', () => {
1212
const ast = {
1313
kind: 'ScalarTypeDefinition',
1414
name: { kind: 'Name', value: 'foo' },
15-
};
15+
} as const;
1616
expect(print(ast)).to.equal('scalar foo');
1717
});
1818

src/language/__tests__/toJSONDeep.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export function toJSONDeep(value: unknown): unknown {
1111
}
1212

1313
if (typeof value.toJSON === 'function') {
14-
// @ts-expect-error
1514
return value.toJSON();
1615
}
1716

src/language/__tests__/visitor-test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { describe, it } from 'mocha';
44
import { kitchenSinkQuery } from '../../__testUtils__/kitchenSinkQuery';
55

66
import type { ASTNode } from '../ast';
7+
import { isNode } from '../ast';
78
import { Kind } from '../kinds';
89
import { parse } from '../parser';
910
import { visit, visitInParallel, BREAK } from '../visitor';
@@ -50,6 +51,7 @@ function checkVisitorFnArgs(ast: any, args: any, isEdited: boolean = false) {
5051
}
5152

5253
function getValue(node: ASTNode) {
54+
// @ts-expect-error FIXME
5355
return node.value != null ? node.value : undefined;
5456
}
5557

@@ -263,6 +265,7 @@ describe('Visitor', () => {
263265
if (node.kind === 'Field' && node.name.value === 'a') {
264266
return {
265267
kind: 'Field',
268+
// @ts-expect-error FIXME
266269
selectionSet: [addedField].concat(node.selectionSet),
267270
};
268271
}
@@ -522,7 +525,7 @@ describe('Visitor', () => {
522525
'enter',
523526
node.kind,
524527
key,
525-
parent?.kind != null ? parent.kind : undefined,
528+
isNode(parent) ? parent.kind : undefined,
526529
]);
527530

528531
checkVisitorFnArgs(ast, arguments);
@@ -534,7 +537,7 @@ describe('Visitor', () => {
534537
'leave',
535538
node.kind,
536539
key,
537-
parent?.kind != null ? parent.kind : undefined,
540+
isNode(parent) ? parent.kind : undefined,
538541
]);
539542

540543
expect(argsStack.pop()).to.deep.equal([...arguments]);

src/language/ast.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ export class Token {
125125
* @internal
126126
*/
127127
export function isNode(maybeNode: unknown): maybeNode is ASTNode {
128-
return maybeNode != null && typeof maybeNode.kind === 'string';
128+
// eslint-disable-next-line @typescript-eslint/dot-notation
129+
return typeof maybeNode?.['kind'] === 'string';
129130
}
130131

131132
/**

src/language/parser.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ export class Parser {
440440
}
441441

442442
parseConstArgument(): ConstArgumentNode {
443-
// @ts-expect-error FIXME during TS conversion
444443
return this.parseArgument(true);
445444
}
446445

@@ -610,7 +609,6 @@ export class Parser {
610609
}
611610

612611
parseConstValueLiteral(): ConstValueNode {
613-
// @ts-expect-error FIXME during TS conversion
614612
return this.parseValueLiteral(true);
615613
}
616614

@@ -695,7 +693,6 @@ export class Parser {
695693
}
696694

697695
parseConstDirectives(): Array<ConstDirectiveNode> {
698-
// @ts-expect-error FIXME during TS conversion
699696
return this.parseDirectives(true);
700697
}
701698

src/language/printLocation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function printSourceLocation(
3838
if (locationLine.length > 120) {
3939
const subLineIndex = Math.floor(columnNum / 80);
4040
const subLineColumnNum = columnNum % 80;
41-
const subLines = [];
41+
const subLines: Array<string> = [];
4242
for (let i = 0; i < locationLine.length; i += 80) {
4343
subLines.push(locationLine.slice(i, i + 80));
4444
}
@@ -47,8 +47,11 @@ export function printSourceLocation(
4747
locationStr +
4848
printPrefixedLines([
4949
[`${lineNum} |`, subLines[0]],
50+
// @ts-expect-error FIXME
5051
...subLines.slice(1, subLineIndex + 1).map((subLine) => ['|', subLine]),
52+
// @ts-expect-error FIXME
5153
['|', '^'.padStart(subLineColumnNum)],
54+
// @ts-expect-error FIXME
5255
['|', subLines[subLineIndex + 1]],
5356
])
5457
);

src/subscription/__tests__/mapAsyncIterator-test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ describe('mapAsyncIterator', () => {
105105
expect(await doubles.next()).to.deep.equal({ value: 4, done: false });
106106

107107
// Early return
108+
// @ts-expect-error FIXME: TS Conversion
108109
expect(await doubles.return()).to.deep.equal({
109110
value: 'The End',
110111
done: true,
@@ -142,6 +143,7 @@ describe('mapAsyncIterator', () => {
142143
expect(await doubles.next()).to.deep.equal({ value: 4, done: false });
143144

144145
// Early return
146+
// @ts-expect-error FIXME: TS Conversion
145147
expect(await doubles.return()).to.deep.equal({
146148
value: undefined,
147149
done: true,
@@ -151,11 +153,11 @@ describe('mapAsyncIterator', () => {
151153
it('passes through early return from async values', async () => {
152154
async function* source() {
153155
try {
154-
yield 1;
155-
yield 2;
156+
yield 'a';
157+
yield 'b';
156158

157159
// istanbul ignore next (Shouldn't be reached)
158-
yield 3;
160+
yield 'c';
159161
} finally {
160162
yield 'Done';
161163
yield 'Last';
@@ -164,8 +166,8 @@ describe('mapAsyncIterator', () => {
164166

165167
const doubles = mapAsyncIterator(source(), (x) => x + x);
166168

167-
expect(await doubles.next()).to.deep.equal({ value: 2, done: false });
168-
expect(await doubles.next()).to.deep.equal({ value: 4, done: false });
169+
expect(await doubles.next()).to.deep.equal({ value: 'aa', done: false });
170+
expect(await doubles.next()).to.deep.equal({ value: 'bb', done: false });
169171

170172
// Early return
171173
expect(await doubles.return()).to.deep.equal({

src/subscription/__tests__/subscribe-test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ describe('Subscription Initialization Phase', () => {
482482
// Once a subscription returns a valid AsyncIterator, it can still yield errors.
483483
describe('Subscription Publish Phase', () => {
484484
it('produces a payload for multiple subscribe in same subscription', async () => {
485-
const pubsub = new SimplePubSub();
485+
const pubsub = new SimplePubSub<Email>();
486486

487487
const subscription = await createSubscription(pubsub);
488488
invariant(isAsyncIterable(subscription));
@@ -525,7 +525,7 @@ describe('Subscription Publish Phase', () => {
525525
});
526526

527527
it('produces a payload per subscription event', async () => {
528-
const pubsub = new SimplePubSub();
528+
const pubsub = new SimplePubSub<Email>();
529529
const subscription = await createSubscription(pubsub);
530530
invariant(isAsyncIterable(subscription));
531531

@@ -614,7 +614,7 @@ describe('Subscription Publish Phase', () => {
614614
});
615615

616616
it('produces a payload when there are multiple events', async () => {
617-
const pubsub = new SimplePubSub();
617+
const pubsub = new SimplePubSub<Email>();
618618
const subscription = await createSubscription(pubsub);
619619
invariant(isAsyncIterable(subscription));
620620

@@ -680,7 +680,7 @@ describe('Subscription Publish Phase', () => {
680680
});
681681

682682
it('should not trigger when subscription is already done', async () => {
683-
const pubsub = new SimplePubSub();
683+
const pubsub = new SimplePubSub<Email>();
684684
const subscription = await createSubscription(pubsub);
685685
invariant(isAsyncIterable(subscription));
686686

@@ -734,7 +734,7 @@ describe('Subscription Publish Phase', () => {
734734
});
735735

736736
it('should not trigger when subscription is thrown', async () => {
737-
const pubsub = new SimplePubSub();
737+
const pubsub = new SimplePubSub<Email>();
738738
const subscription = await createSubscription(pubsub);
739739
invariant(isAsyncIterable(subscription));
740740

@@ -786,7 +786,7 @@ describe('Subscription Publish Phase', () => {
786786
});
787787

788788
it('event order is correct for multiple publishes', async () => {
789-
const pubsub = new SimplePubSub();
789+
const pubsub = new SimplePubSub<Email>();
790790
const subscription = await createSubscription(pubsub);
791791
invariant(isAsyncIterable(subscription));
792792

src/type/__tests__/introspection-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,12 +1566,12 @@ describe('Introspection', () => {
15661566
});
15671567

15681568
// istanbul ignore next (Called only to fail test)
1569-
function fieldResolver(_1, _2, _3, info) {
1569+
function fieldResolver(_1, _2, _3, info): never {
15701570
expect.fail(`Called on ${info.parentType.name}::${info.fieldName}`);
15711571
}
15721572

15731573
// istanbul ignore next (Called only to fail test)
1574-
function typeResolver(_1, _2, info) {
1574+
function typeResolver(_1, _2, info): never {
15751575
expect.fail(`Called on ${info.parentType.name}::${info.fieldName}`);
15761576
}
15771577

src/type/definition.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ export function assertListType(type: unknown): GraphQLList<GraphQLType> {
180180
return type;
181181
}
182182

183+
export function isNonNullType(
184+
type: GraphQLInputType,
185+
): type is GraphQLNonNull<GraphQLInputType>;
186+
export function isNonNullType(
187+
type: GraphQLOutputType,
188+
): type is GraphQLNonNull<GraphQLOutputType>;
189+
export function isNonNullType(
190+
type: unknown,
191+
): type is GraphQLNonNull<GraphQLType>;
183192
export function isNonNullType(
184193
type: unknown,
185194
): type is GraphQLNonNull<GraphQLType> {
@@ -819,6 +828,7 @@ function defineFieldMap<TSource, TContext>(
819828
`${config.name} fields must be an object with field names as keys or a function which returns such an object.`,
820829
);
821830

831+
// @ts-expect-error FIXME: TS Conversion
822832
return mapValue(fieldMap, (fieldConfig, fieldName) => {
823833
devAssert(
824834
isPlainObj(fieldConfig),

src/type/introspection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,19 @@ export const __Type: GraphQLObjectType = new GraphQLObjectType({
234234
},
235235
name: {
236236
type: GraphQLString,
237+
// @ts-expect-error FIXME: TS Conversion
237238
resolve: (type) => (type.name !== undefined ? type.name : undefined),
238239
},
239240
description: {
240241
type: GraphQLString,
241242
resolve: (type) =>
243+
// @ts-expect-error FIXME: TS Conversion
242244
type.description !== undefined ? type.description : undefined,
243245
},
244246
specifiedByURL: {
245247
type: GraphQLString,
246248
resolve: (obj) =>
249+
// @ts-expect-error FIXME: TS Conversion
247250
obj.specifiedByURL !== undefined ? obj.specifiedByURL : undefined,
248251
},
249252
fields: {
@@ -310,6 +313,7 @@ export const __Type: GraphQLObjectType = new GraphQLObjectType({
310313
ofType: {
311314
type: __Type,
312315
resolve: (type) =>
316+
// @ts-expect-error FIXME: TS Conversion
313317
type.ofType !== undefined ? type.ofType : undefined,
314318
},
315319
} as GraphQLFieldConfigMap<GraphQLType, unknown>),

src/type/scalars.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ function serializeObject(outputValue: unknown): unknown {
139139
}
140140
}
141141
if (typeof outputValue.toJSON === 'function') {
142-
// @ts-expect-error
143142
return outputValue.toJSON();
144143
}
145144
}

0 commit comments

Comments
 (0)