Skip to content

Commit 26bf00a

Browse files
committed
TS: Fix strict issues in src/jsutils
1 parent 2fadef3 commit 26bf00a

File tree

8 files changed

+32
-25
lines changed

8 files changed

+32
-25
lines changed

src/jsutils/__tests__/identityFunc-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { identityFunc } from '../identityFunc';
55

66
describe('identityFunc', () => {
77
it('returns the first argument it receives', () => {
8-
// @ts-expect-error FIXME: TS Conversion
8+
// @ts-expect-error (Expects an argument)
99
expect(identityFunc()).to.equal(undefined);
1010
expect(identityFunc(undefined)).to.equal(undefined);
1111
expect(identityFunc(null)).to.equal(null);

src/jsutils/__tests__/inspect-test.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ describe('inspect', () => {
132132
'{ self: [Circular], deepSelf: { self: [Circular] } }',
133133
);
134134

135-
const array = [];
135+
const array: any = [];
136136
array[0] = array;
137137
array[1] = [array];
138138

139139
expect(inspect(array)).to.equal('[[Circular], [[Circular]]]');
140140

141-
const mixed = { array: [] };
141+
const mixed: any = { array: [] };
142142
mixed.array[0] = mixed;
143143

144144
expect(inspect(mixed)).to.equal('{ array: [[Circular]] }');
@@ -165,14 +165,21 @@ describe('inspect', () => {
165165

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

168-
Foo.prototype[Symbol.toStringTag] = 'Bar';
169-
expect(inspect([[new Foo()]])).to.equal('[[[Bar]]]');
168+
class Foo2 {
169+
foo: string;
170+
171+
[Symbol.toStringTag] = 'Bar';
172+
173+
constructor() {
174+
this.foo = 'bar';
175+
}
176+
}
177+
expect(inspect([[new Foo2()]])).to.equal('[[[Bar]]]');
170178

171179
// eslint-disable-next-line func-names
172-
const objectWithoutClassName = new (function () {
173-
// eslint-disable-next-line @typescript-eslint/no-invalid-this
180+
const objectWithoutClassName = new (function (this: any) {
174181
this.foo = 1;
175-
})();
182+
} as any)();
176183
expect(inspect([[objectWithoutClassName]])).to.equal('[[[Object]]]');
177184
});
178185
});

src/jsutils/didYouMean.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ export function didYouMean(
1212
firstArg: string | ReadonlyArray<string>,
1313
secondArg?: ReadonlyArray<string>,
1414
) {
15-
const [subMessage, suggestionsArg] =
16-
typeof firstArg === 'string'
17-
? [firstArg, secondArg]
18-
: [undefined, firstArg];
15+
const [subMessage, suggestionsArg] = secondArg
16+
? [firstArg as string, secondArg]
17+
: [undefined, firstArg as ReadonlyArray<string>];
1918

2019
let message = ' Did you mean ';
2120
if (subMessage) {

src/jsutils/inspect.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function formatValue(value: unknown, seenValues: Array<unknown>): string {
2222
}
2323

2424
function formatObjectValue(
25-
value: Object,
25+
value: object | null,
2626
previouslySeenValues: Array<unknown>,
2727
): string {
2828
if (value === null) {
@@ -35,10 +35,8 @@ function formatObjectValue(
3535

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

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

4341
// check for infinite recursion
4442
if (jsonValue !== value) {
@@ -53,7 +51,11 @@ function formatObjectValue(
5351
return formatObject(value, seenValues);
5452
}
5553

56-
function formatObject(object: Object, seenValues: Array<unknown>): string {
54+
function isJSONable(value: any): value is { toJSON: () => unknown } {
55+
return typeof value.toJSON === 'function';
56+
}
57+
58+
function formatObject(object: object, seenValues: Array<unknown>): string {
5759
const entries = Object.entries(object);
5860
if (entries.length === 0) {
5961
return '{}';
@@ -98,7 +100,7 @@ function formatArray(
98100
return '[' + items.join(', ') + ']';
99101
}
100102

101-
function getObjectTag(object: Object): string {
103+
function getObjectTag(object: object): string {
102104
const tag = Object.prototype.toString
103105
.call(object)
104106
.replace(/^\[object /, '')

src/jsutils/isAsyncIterable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* implementing a `Symbol.asyncIterator` method.
44
*/
55
export function isAsyncIterable(
6-
maybeAsyncIterable: unknown,
6+
maybeAsyncIterable: any,
77
): maybeAsyncIterable is AsyncIterable<unknown> {
88
return typeof maybeAsyncIterable?.[Symbol.asyncIterator] === 'function';
99
}

src/jsutils/isIterableObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* isIterableObject({ length: 1, 0: 'Alpha' }) // false
1616
*/
1717
export function isIterableObject(
18-
maybeIterable: unknown,
18+
maybeIterable: any,
1919
): maybeIterable is Iterable<unknown> {
2020
return (
2121
typeof maybeIterable === 'object' &&

src/jsutils/isPromise.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Returns true if the value acts like a Promise, i.e. has a "then" function,
33
* otherwise returns false.
44
*/
5-
export function isPromise(value: unknown): value is Promise<unknown> {
6-
// eslint-disable-next-line @typescript-eslint/dot-notation
7-
return typeof value?.['then'] === 'function';
5+
export function isPromise(value: any): value is Promise<unknown> {
6+
return typeof value?.then === 'function';
87
}

src/jsutils/memoize3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function memoize3<
77
A3 extends object,
88
R,
99
>(fn: (a1: A1, a2: A2, a3: A3) => R): (a1: A1, a2: A2, a3: A3) => R {
10-
let cache0;
10+
let cache0: WeakMap<A1, WeakMap<A2, WeakMap<A3, R>>>;
1111

1212
return function memoized(a1, a2, a3) {
1313
if (cache0 === undefined) {

0 commit comments

Comments
 (0)