Skip to content

Commit

Permalink
Fix TSC errors
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed May 24, 2021
1 parent f6655ec commit baa6a5d
Show file tree
Hide file tree
Showing 33 changed files with 99 additions and 47 deletions.
6 changes: 4 additions & 2 deletions src/error/GraphQLError.ts
Expand Up @@ -98,8 +98,10 @@ export class GraphQLError extends Error {
_source = _nodes[0].loc?.source;
}

let _positions = positions;
if (!_positions && _nodes) {
let _positions;
if (positions) {
_positions = positions;
} else if (_nodes) {
_positions = [];
for (const node of _nodes) {
if (node.loc) {
Expand Down
1 change: 1 addition & 0 deletions src/error/locatedError.ts
Expand Up @@ -22,6 +22,7 @@ export function locatedError(
: new Error('Unexpected error value: ' + inspect(rawOriginalError));

// Note: this uses a brand-check to support GraphQL errors originating from other contexts.
// @ts-expect-error FIXME: TS Conversion
if (Array.isArray(originalError.path)) {
// @ts-expect-error
return originalError;
Expand Down
5 changes: 3 additions & 2 deletions src/execution/execute.ts
Expand Up @@ -191,7 +191,9 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
// field and its descendants will be omitted, and sibling fields will still
// be executed. An execution which encounters errors will still result in a
// resolved Promise.
// @ts-expect-error FIXME: TS Conversion
const data = executeOperation(exeContext, exeContext.operation, rootValue);
// @ts-expect-error FIXME: TS Conversion
return buildResponse(exeContext, data);
}

Expand Down Expand Up @@ -313,7 +315,6 @@ export function buildExecutionContext(
return coercedVariableValues.errors;
}

// @ts-expect-error
return {
schema,
fragments,
Expand Down Expand Up @@ -1078,7 +1079,7 @@ function _collectSubfields(
fieldNodes: ReadonlyArray<FieldNode>,
): Map<string, Array<FieldNode>> {
let subFieldNodes = new Map();
const visitedFragmentNames = new Set();
const visitedFragmentNames = new Set<string>();
for (const node of fieldNodes) {
if (node.selectionSet) {
subFieldNodes = collectFields(
Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/__tests__/inspect-test.ts
Expand Up @@ -124,7 +124,7 @@ describe('inspect', () => {
});

it('detect circular objects', () => {
const obj = {};
const obj: { [name: string]: unknown } = {};
obj.self = obj;
obj.deepSelf = { self: obj };

Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/__tests__/isIterableObject-test.ts
Expand Up @@ -60,7 +60,7 @@ describe('isIterableObject', () => {
};
expect(isIterableObject(invalidIterable)).to.equal(false);

const arrayLike = {};
const arrayLike: { [key: string]: unknown } = {};
arrayLike[0] = 'Alpha';
arrayLike[1] = 'Bravo';
arrayLike[2] = 'Charlie';
Expand Down
2 changes: 2 additions & 0 deletions src/jsutils/inspect.ts
Expand Up @@ -35,7 +35,9 @@ function formatObjectValue(

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

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

// check for infinite recursion
Expand Down
3 changes: 2 additions & 1 deletion src/jsutils/isPromise.ts
Expand Up @@ -3,5 +3,6 @@
* otherwise returns false.
*/
export function isPromise(value: unknown): value is Promise<unknown> {
return typeof value?.then === 'function';
// eslint-disable-next-line @typescript-eslint/dot-notation
return typeof value?.['then'] === 'function';
}
5 changes: 4 additions & 1 deletion src/language/__tests__/printer-test.ts
Expand Up @@ -9,7 +9,10 @@ import { print } from '../printer';

describe('Printer: Query document', () => {
it('prints minimal ast', () => {
const ast = { kind: 'Field', name: { kind: 'Name', value: 'foo' } };
const ast = {
kind: 'Field',
name: { kind: 'Name', value: 'foo' },
} as const;
expect(print(ast)).to.equal('foo');
});

Expand Down
2 changes: 1 addition & 1 deletion src/language/__tests__/schema-printer-test.ts
Expand Up @@ -12,7 +12,7 @@ describe('Printer: SDL document', () => {
const ast = {
kind: 'ScalarTypeDefinition',
name: { kind: 'Name', value: 'foo' },
};
} as const;
expect(print(ast)).to.equal('scalar foo');
});

Expand Down
1 change: 0 additions & 1 deletion src/language/__tests__/toJSONDeep.ts
Expand Up @@ -11,7 +11,6 @@ export function toJSONDeep(value: unknown): unknown {
}

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

Expand Down
7 changes: 5 additions & 2 deletions src/language/__tests__/visitor-test.ts
Expand Up @@ -4,6 +4,7 @@ import { describe, it } from 'mocha';
import { kitchenSinkQuery } from '../../__testUtils__/kitchenSinkQuery';

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

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

Expand Down Expand Up @@ -263,6 +265,7 @@ describe('Visitor', () => {
if (node.kind === 'Field' && node.name.value === 'a') {
return {
kind: 'Field',
// @ts-expect-error FIXME
selectionSet: [addedField].concat(node.selectionSet),
};
}
Expand Down Expand Up @@ -522,7 +525,7 @@ describe('Visitor', () => {
'enter',
node.kind,
key,
parent?.kind != null ? parent.kind : undefined,
isNode(parent) ? parent.kind : undefined,
]);

checkVisitorFnArgs(ast, arguments);
Expand All @@ -534,7 +537,7 @@ describe('Visitor', () => {
'leave',
node.kind,
key,
parent?.kind != null ? parent.kind : undefined,
isNode(parent) ? parent.kind : undefined,
]);

expect(argsStack.pop()).to.deep.equal([...arguments]);
Expand Down
3 changes: 2 additions & 1 deletion src/language/ast.ts
Expand Up @@ -125,7 +125,8 @@ export class Token {
* @internal
*/
export function isNode(maybeNode: unknown): maybeNode is ASTNode {
return maybeNode != null && typeof maybeNode.kind === 'string';
// eslint-disable-next-line @typescript-eslint/dot-notation
return typeof maybeNode?.['kind'] === 'string';
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/language/parser.ts
Expand Up @@ -440,7 +440,6 @@ export class Parser {
}

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

Expand Down Expand Up @@ -610,7 +609,6 @@ export class Parser {
}

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

Expand Down Expand Up @@ -695,7 +693,6 @@ export class Parser {
}

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

Expand Down
5 changes: 4 additions & 1 deletion src/language/printLocation.ts
Expand Up @@ -38,7 +38,7 @@ export function printSourceLocation(
if (locationLine.length > 120) {
const subLineIndex = Math.floor(columnNum / 80);
const subLineColumnNum = columnNum % 80;
const subLines = [];
const subLines: Array<string> = [];
for (let i = 0; i < locationLine.length; i += 80) {
subLines.push(locationLine.slice(i, i + 80));
}
Expand All @@ -47,8 +47,11 @@ export function printSourceLocation(
locationStr +
printPrefixedLines([
[`${lineNum} |`, subLines[0]],
// @ts-expect-error FIXME
...subLines.slice(1, subLineIndex + 1).map((subLine) => ['|', subLine]),
// @ts-expect-error FIXME
['|', '^'.padStart(subLineColumnNum)],
// @ts-expect-error FIXME
['|', subLines[subLineIndex + 1]],
])
);
Expand Down
12 changes: 7 additions & 5 deletions src/subscription/__tests__/mapAsyncIterator-test.ts
Expand Up @@ -105,6 +105,7 @@ describe('mapAsyncIterator', () => {
expect(await doubles.next()).to.deep.equal({ value: 4, done: false });

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

// Early return
// @ts-expect-error FIXME: TS Conversion
expect(await doubles.return()).to.deep.equal({
value: undefined,
done: true,
Expand All @@ -151,11 +153,11 @@ describe('mapAsyncIterator', () => {
it('passes through early return from async values', async () => {
async function* source() {
try {
yield 1;
yield 2;
yield 'a';
yield 'b';

// istanbul ignore next (Shouldn't be reached)
yield 3;
yield 'c';
} finally {
yield 'Done';
yield 'Last';
Expand All @@ -164,8 +166,8 @@ describe('mapAsyncIterator', () => {

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

expect(await doubles.next()).to.deep.equal({ value: 2, done: false });
expect(await doubles.next()).to.deep.equal({ value: 4, done: false });
expect(await doubles.next()).to.deep.equal({ value: 'aa', done: false });
expect(await doubles.next()).to.deep.equal({ value: 'bb', done: false });

// Early return
expect(await doubles.return()).to.deep.equal({
Expand Down
12 changes: 6 additions & 6 deletions src/subscription/__tests__/subscribe-test.ts
Expand Up @@ -482,7 +482,7 @@ describe('Subscription Initialization Phase', () => {
// Once a subscription returns a valid AsyncIterator, it can still yield errors.
describe('Subscription Publish Phase', () => {
it('produces a payload for multiple subscribe in same subscription', async () => {
const pubsub = new SimplePubSub();
const pubsub = new SimplePubSub<Email>();

const subscription = await createSubscription(pubsub);
invariant(isAsyncIterable(subscription));
Expand Down Expand Up @@ -525,7 +525,7 @@ describe('Subscription Publish Phase', () => {
});

it('produces a payload per subscription event', async () => {
const pubsub = new SimplePubSub();
const pubsub = new SimplePubSub<Email>();
const subscription = await createSubscription(pubsub);
invariant(isAsyncIterable(subscription));

Expand Down Expand Up @@ -614,7 +614,7 @@ describe('Subscription Publish Phase', () => {
});

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

Expand Down Expand Up @@ -680,7 +680,7 @@ describe('Subscription Publish Phase', () => {
});

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

Expand Down Expand Up @@ -734,7 +734,7 @@ describe('Subscription Publish Phase', () => {
});

it('should not trigger when subscription is thrown', async () => {
const pubsub = new SimplePubSub();
const pubsub = new SimplePubSub<Email>();
const subscription = await createSubscription(pubsub);
invariant(isAsyncIterable(subscription));

Expand Down Expand Up @@ -786,7 +786,7 @@ describe('Subscription Publish Phase', () => {
});

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

Expand Down
4 changes: 2 additions & 2 deletions src/type/__tests__/introspection-test.ts
Expand Up @@ -1566,12 +1566,12 @@ describe('Introspection', () => {
});

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

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

Expand Down
10 changes: 10 additions & 0 deletions src/type/definition.ts
Expand Up @@ -180,6 +180,15 @@ export function assertListType(type: unknown): GraphQLList<GraphQLType> {
return type;
}

export function isNonNullType(
type: GraphQLInputType,
): type is GraphQLNonNull<GraphQLInputType>;
export function isNonNullType(
type: GraphQLOutputType,
): type is GraphQLNonNull<GraphQLOutputType>;
export function isNonNullType(
type: unknown,
): type is GraphQLNonNull<GraphQLType>;
export function isNonNullType(
type: unknown,
): type is GraphQLNonNull<GraphQLType> {
Expand Down Expand Up @@ -819,6 +828,7 @@ function defineFieldMap<TSource, TContext>(
`${config.name} fields must be an object with field names as keys or a function which returns such an object.`,
);

// @ts-expect-error FIXME: TS Conversion
return mapValue(fieldMap, (fieldConfig, fieldName) => {
devAssert(
isPlainObj(fieldConfig),
Expand Down
4 changes: 4 additions & 0 deletions src/type/introspection.ts
Expand Up @@ -234,16 +234,19 @@ export const __Type: GraphQLObjectType = new GraphQLObjectType({
},
name: {
type: GraphQLString,
// @ts-expect-error FIXME: TS Conversion
resolve: (type) => (type.name !== undefined ? type.name : undefined),
},
description: {
type: GraphQLString,
resolve: (type) =>
// @ts-expect-error FIXME: TS Conversion
type.description !== undefined ? type.description : undefined,
},
specifiedByURL: {
type: GraphQLString,
resolve: (obj) =>
// @ts-expect-error FIXME: TS Conversion
obj.specifiedByURL !== undefined ? obj.specifiedByURL : undefined,
},
fields: {
Expand Down Expand Up @@ -310,6 +313,7 @@ export const __Type: GraphQLObjectType = new GraphQLObjectType({
ofType: {
type: __Type,
resolve: (type) =>
// @ts-expect-error FIXME: TS Conversion
type.ofType !== undefined ? type.ofType : undefined,
},
} as GraphQLFieldConfigMap<GraphQLType, unknown>),
Expand Down
1 change: 0 additions & 1 deletion src/type/scalars.ts
Expand Up @@ -139,7 +139,6 @@ function serializeObject(outputValue: unknown): unknown {
}
}
if (typeof outputValue.toJSON === 'function') {
// @ts-expect-error
return outputValue.toJSON();
}
}
Expand Down

0 comments on commit baa6a5d

Please sign in to comment.