Skip to content

Commit 8a70302

Browse files
saihajIvanGoncharov
authored andcommitted
Switch to TS syntax (#3090)
1 parent ecaf310 commit 8a70302

File tree

114 files changed

+1346
-1299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+1346
-1299
lines changed

old_dts/utilities/astFromValue.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { GraphQLInputType } from '../type/definition';
1414
* | Boolean | Boolean |
1515
* | String | String / Enum Value |
1616
* | Number | Int / Float |
17-
* | Mixed | Enum Value |
17+
* | Unknown | Enum Value |
1818
* | null | NullValue |
1919
*
2020
*/

old_dts/utilities/valueFromAST.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type { GraphQLInputType } from '../type/definition';
1818
* | Boolean | Boolean |
1919
* | String | String |
2020
* | Int / Float | Number |
21-
* | Enum Value | Mixed |
21+
* | Enum Value | Unknown |
2222
* | NullValue | null |
2323
*
2424
*/

src/__testUtils__/dedent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export function dedentString(string: string): string {
2727
* str === "{\n test\n}";
2828
*/
2929
export function dedent(
30-
strings: $ReadOnlyArray<string>,
31-
...values: $ReadOnlyArray<string>
30+
strings: ReadonlyArray<string>,
31+
...values: ReadonlyArray<string>
3232
): string {
3333
let str = strings[0];
3434

src/__testUtils__/inspectStr.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import type { Maybe } from '../jsutils/Maybe';
2+
13
/**
24
* Special inspect function to produce readable string literal for error messages in tests
35
*/
4-
export function inspectStr(str: ?string): string {
6+
export function inspectStr(str: Maybe<string>): string {
57
if (str == null) {
68
return 'null';
79
}

src/__tests__/starWarsData.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export type Character = {
77
name: string;
88
friends: Array<string>;
99
appearsIn: Array<number>;
10-
...
1110
};
1211

1312
export type Human = {

src/error/GraphQLError.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// flowlint uninitialized-instance-property:off
33

44
import { isObjectLike } from '../jsutils/isObjectLike';
5+
import type { Maybe } from '../jsutils/Maybe';
56

67
import type { ASTNode } from '../language/ast';
78
import type { Source } from '../language/source';
@@ -35,53 +36,53 @@ export class GraphQLError extends Error {
3536
*
3637
* Enumerable, and appears in the result of JSON.stringify().
3738
*/
38-
+locations: $ReadOnlyArray<SourceLocation> | void;
39+
readonly locations?: ReadonlyArray<SourceLocation>;
3940

4041
/**
4142
* An array describing the JSON-path into the execution response which
4243
* corresponds to this error. Only included for errors during execution.
4344
*
4445
* Enumerable, and appears in the result of JSON.stringify().
4546
*/
46-
+path: $ReadOnlyArray<string | number> | void;
47+
readonly path?: ReadonlyArray<string | number>;
4748

4849
/**
4950
* An array of GraphQL AST Nodes corresponding to this error.
5051
*/
51-
+nodes: $ReadOnlyArray<ASTNode> | void;
52+
readonly nodes?: ReadonlyArray<ASTNode>;
5253

5354
/**
5455
* The source GraphQL document for the first location of this error.
5556
*
5657
* Note that if this Error represents more than one node, the source may not
5758
* represent nodes after the first node.
5859
*/
59-
+source: Source | void;
60+
readonly source?: Source;
6061

6162
/**
6263
* An array of character offsets within the source GraphQL document
6364
* which correspond to this error.
6465
*/
65-
+positions: $ReadOnlyArray<number> | void;
66+
readonly positions?: ReadonlyArray<number>;
6667

6768
/**
6869
* The original error thrown from a field resolver during execution.
6970
*/
70-
+originalError: ?Error;
71+
readonly originalError: Maybe<Error>;
7172

7273
/**
7374
* Extension fields to add to the formatted error.
7475
*/
75-
+extensions: { [key: string]: mixed; ... } | void;
76+
readonly extensions?: { [key: string]: unknown };
7677

7778
constructor(
7879
message: string,
79-
nodes?: $ReadOnlyArray<ASTNode> | ASTNode | void | null,
80-
source?: ?Source,
81-
positions?: ?$ReadOnlyArray<number>,
82-
path?: ?$ReadOnlyArray<string | number>,
83-
originalError?: ?(Error & { +extensions?: mixed; ... }),
84-
extensions?: ?{ [key: string]: mixed; ... },
80+
nodes?: ReadonlyArray<ASTNode> | ASTNode | null,
81+
source?: Maybe<Source>,
82+
positions?: Maybe<ReadonlyArray<number>>,
83+
path?: Maybe<ReadonlyArray<string | number>>,
84+
originalError?: Maybe<Error & { readonly extensions?: unknown }>,
85+
extensions?: Maybe<{ [key: string]: unknown }>,
8586
) {
8687
super(message);
8788

src/error/__tests__/formatError-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GraphQLError } from '../GraphQLError';
66

77
describe('formatError: default error formatter', () => {
88
it('uses default message', () => {
9-
// $FlowExpectedError[incompatible-call]
9+
// @ts-expect-error
1010
const e = new GraphQLError();
1111

1212
expect(formatError(e)).to.deep.equal({
@@ -45,12 +45,12 @@ describe('formatError: default error formatter', () => {
4545
});
4646

4747
it('rejects null and undefined errors', () => {
48-
// $FlowExpectedError[incompatible-call]
48+
// @ts-expect-error
4949
expect(() => formatError(undefined)).to.throw(
5050
'Received null or undefined error.',
5151
);
5252

53-
// $FlowExpectedError[incompatible-call]
53+
// @ts-expect-error
5454
expect(() => formatError(null)).to.throw(
5555
'Received null or undefined error.',
5656
);

src/error/__tests__/locatedError-test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ describe('locatedError', () => {
1818

1919
it('passes GraphQLError-ish through', () => {
2020
const e = new Error();
21-
// $FlowExpectedError[prop-missing]
21+
// @ts-expect-error
2222
e.locations = [];
23-
// $FlowExpectedError[prop-missing]
23+
// @ts-expect-error
2424
e.path = [];
25-
// $FlowExpectedError[prop-missing]
25+
// @ts-expect-error
2626
e.nodes = [];
27-
// $FlowExpectedError[prop-missing]
27+
// @ts-expect-error
2828
e.source = null;
29-
// $FlowExpectedError[prop-missing]
29+
// @ts-expect-error
3030
e.positions = [];
3131
e.name = 'GraphQLError';
3232

@@ -35,7 +35,7 @@ describe('locatedError', () => {
3535

3636
it('does not pass through elasticsearch-like errors', () => {
3737
const e = new Error('I am from elasticsearch');
38-
// $FlowExpectedError[prop-missing]
38+
// @ts-expect-error
3939
e.path = '/something/feed/_search';
4040

4141
expect(locatedError(e, [], [])).to.not.deep.equal(e);

src/error/formatError.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ export type GraphQLFormattedError = {
2929
* from occurrence to occurrence of the problem, except for purposes of
3030
* localization.
3131
*/
32-
+message: string;
32+
readonly message: string;
3333
/**
3434
* If an error can be associated to a particular point in the requested
3535
* GraphQL document, it should contain a list of locations.
3636
*/
37-
+locations: $ReadOnlyArray<SourceLocation> | void;
37+
readonly locations?: ReadonlyArray<SourceLocation>;
3838
/**
3939
* If an error can be associated to a particular field in the GraphQL result,
4040
* it _must_ contain an entry with the key `path` that details the path of
4141
* the response field which experienced the error. This allows clients to
4242
* identify whether a null result is intentional or caused by a runtime error.
4343
*/
44-
+path: $ReadOnlyArray<string | number> | void;
44+
readonly path?: ReadonlyArray<string | number>;
4545
/**
4646
* Reserved for implementors to extend the protocol however they see fit,
4747
* and hence there are no additional restrictions on its contents.
4848
*/
49-
+extensions?: { [key: string]: mixed; ... };
49+
readonly extensions?: { [key: string]: unknown };
5050
};

src/error/locatedError.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { inspect } from '../jsutils/inspect';
2+
import type { Maybe } from '../jsutils/Maybe';
23

34
import type { ASTNode } from '../language/ast';
45

@@ -10,9 +11,9 @@ import { GraphQLError } from './GraphQLError';
1011
* document responsible for the original Error.
1112
*/
1213
export function locatedError(
13-
rawOriginalError: mixed,
14-
nodes: ASTNode | $ReadOnlyArray<ASTNode> | void | null,
15-
path?: ?$ReadOnlyArray<string | number>,
14+
rawOriginalError: unknown,
15+
nodes: ASTNode | ReadonlyArray<ASTNode> | undefined | null,
16+
path?: Maybe<ReadonlyArray<string | number>>,
1617
): GraphQLError {
1718
// Sometimes a non-error is thrown, wrap it as an Error instance to ensure a consistent Error interface.
1819
const originalError: Error | GraphQLError =
@@ -22,7 +23,7 @@ export function locatedError(
2223

2324
// Note: this uses a brand-check to support GraphQL errors originating from other contexts.
2425
if (Array.isArray(originalError.path)) {
25-
// $FlowExpectedError[incompatible-return]
26+
// @ts-expect-error
2627
return originalError;
2728
}
2829

0 commit comments

Comments
 (0)