Skip to content

Commit 69b4c59

Browse files
committed
TS: Fix strict issues in src/error
1 parent 8066ac9 commit 69b4c59

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

src/__tests__/starWarsSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const episodeEnum = new GraphQLEnumType({
9898
* secretBackstory: String
9999
* }
100100
*/
101-
const characterInterface = new GraphQLInterfaceType({
101+
const characterInterface: GraphQLInterfaceType = new GraphQLInterfaceType({
102102
name: 'Character',
103103
description: 'A character in the Star Wars Trilogy',
104104
fields: () => ({

src/error/GraphQLError.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ import { printLocation, printSourceLocation } from '../language/printLocation';
1414
* GraphQL document and/or execution result that correspond to the Error.
1515
*/
1616
export class GraphQLError extends Error {
17-
/**
18-
* A message describing the Error for debugging purposes.
19-
*
20-
* Enumerable, and appears in the result of JSON.stringify().
21-
*
22-
* Note: should be treated as readonly, despite invariant usage.
23-
*/
24-
message: string;
25-
2617
/**
2718
* An array of { line, column } locations within the source GraphQL document
2819
* which correspond to this error.

src/error/__tests__/formatError-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ describe('formatError: default error formatter', () => {
4545
});
4646

4747
it('rejects null and undefined errors', () => {
48+
// TODO ts-expect-error (formatError expects a value)
4849
expect(() => formatError(undefined)).to.throw(
4950
'Received null or undefined error.',
5051
);
5152

53+
// TODO ts-expect-error (formatError expects a value)
5254
expect(() => formatError(null)).to.throw(
5355
'Received null or undefined error.',
5456
);

src/error/locatedError.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,20 @@ 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
26-
if (Array.isArray(originalError.path)) {
27-
// @ts-expect-error
25+
if (isLocatedGraphQLError(originalError)) {
2826
return originalError;
2927
}
3028

3129
return new GraphQLError(
3230
originalError.message,
33-
// @ts-expect-error FIXME
34-
originalError.nodes ?? nodes,
35-
// @ts-expect-error FIXME
36-
originalError.source,
37-
// @ts-expect-error FIXME
38-
originalError.positions,
31+
(originalError as GraphQLError).nodes ?? nodes,
32+
(originalError as GraphQLError).source,
33+
(originalError as GraphQLError).positions,
3934
path,
4035
originalError,
4136
);
4237
}
38+
39+
function isLocatedGraphQLError(error: any): error is GraphQLError {
40+
return Array.isArray(error.path);
41+
}

0 commit comments

Comments
 (0)