Skip to content

Commit

Permalink
Fix TSC errors
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj authored and IvanGoncharov committed May 24, 2021
1 parent 5708fbc commit 9271b32
Show file tree
Hide file tree
Showing 46 changed files with 199 additions and 98 deletions.
8 changes: 4 additions & 4 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 Expand Up @@ -131,7 +133,6 @@ export class GraphQLError extends Error {
}
}

// @ts-expect-error FIXME
Object.defineProperties(this, {
name: { value: 'GraphQLError' },
message: {
Expand Down Expand Up @@ -210,7 +211,6 @@ export class GraphQLError extends Error {
}

// FIXME: workaround to not break chai comparisons, should be remove in v16
// @ts-expect-error Flow doesn't support computed properties yet
get [Symbol.toStringTag](): string {
return 'Object';
}
Expand Down
2 changes: 0 additions & 2 deletions src/error/__tests__/formatError-test.ts
Expand Up @@ -45,12 +45,10 @@ describe('formatError: default error formatter', () => {
});

it('rejects null and undefined errors', () => {
// @ts-expect-error
expect(() => formatError(undefined)).to.throw(
'Received null or undefined error.',
);

// @ts-expect-error
expect(() => formatError(null)).to.throw(
'Received null or undefined error.',
);
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
1 change: 1 addition & 0 deletions src/jsutils/__tests__/identityFunc-test.ts
Expand Up @@ -5,6 +5,7 @@ import { identityFunc } from '../identityFunc';

describe('identityFunc', () => {
it('returns the first argument it receives', () => {
// @ts-expect-error
expect(identityFunc()).to.equal(undefined);
expect(identityFunc(undefined)).to.equal(undefined);
expect(identityFunc(null)).to.equal(null);
Expand Down
3 changes: 1 addition & 2 deletions 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 Expand Up @@ -165,7 +165,6 @@ describe('inspect', () => {

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

// @ts-expect-error
Foo.prototype[Symbol.toStringTag] = 'Bar';
expect(inspect([[new Foo()]])).to.equal('[[[Bar]]]');

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

0 comments on commit 9271b32

Please sign in to comment.