From 8099201dd0f2ce05c3f9a3030fb6a6f1784ad3e5 Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Wed, 26 May 2021 22:27:24 -0700 Subject: [PATCH] TS: Enable strict mode --- src/error/__tests__/formatError-test.ts | 4 ++-- src/execution/__tests__/abstract-test.ts | 6 +++--- src/language/ast.ts | 2 +- src/subscription/__tests__/subscribe-test.ts | 4 ++-- src/subscription/mapAsyncIterator.ts | 1 - src/type/__tests__/definition-test.ts | 12 ++++++------ src/type/__tests__/validation-test.ts | 10 +++++----- src/utilities/__tests__/buildASTSchema-test.ts | 2 +- src/utilities/__tests__/buildClientSchema-test.ts | 2 +- src/utilities/__tests__/extendSchema-test.ts | 2 +- src/utilities/extendSchema.ts | 2 +- src/validation/__tests__/validation-test.ts | 2 +- tsconfig.json | 5 +---- 13 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/error/__tests__/formatError-test.ts b/src/error/__tests__/formatError-test.ts index 9ea5e946ef4..b0798c958e0 100644 --- a/src/error/__tests__/formatError-test.ts +++ b/src/error/__tests__/formatError-test.ts @@ -45,12 +45,12 @@ describe('formatError: default error formatter', () => { }); it('rejects null and undefined errors', () => { - // TODO ts-expect-error (formatError expects a value) + // @ts-expect-error (formatError expects a value) expect(() => formatError(undefined)).to.throw( 'Received null or undefined error.', ); - // TODO ts-expect-error (formatError expects a value) + // @ts-expect-error (formatError expects a value) expect(() => formatError(null)).to.throw( 'Received null or undefined error.', ); diff --git a/src/execution/__tests__/abstract-test.ts b/src/execution/__tests__/abstract-test.ts index bfbd666b087..0dd097f5275 100644 --- a/src/execution/__tests__/abstract-test.ts +++ b/src/execution/__tests__/abstract-test.ts @@ -577,9 +577,9 @@ describe('Execute: Handles execution of abstract types', () => { ); // FIXME: workaround since we can't inject resolveType into SDL - assertInterfaceType(schema.getType('Pet')).resolveType = - // @ts-expect-error - () => schema.getType('Cat'); + // @ts-expect-error + assertInterfaceType(schema.getType('Pet')).resolveType = () => + schema.getType('Cat'); expectError({ forTypeName: undefined }).toEqual( 'Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.', ); diff --git a/src/language/ast.ts b/src/language/ast.ts index 5e72533c28a..77cdf06de54 100644 --- a/src/language/ast.ts +++ b/src/language/ast.ts @@ -104,7 +104,7 @@ export class Token { this.end = end; this.line = line; this.column = column; - this.value = value; + this.value = value as string; this.prev = prev; this.next = null; } diff --git a/src/subscription/__tests__/subscribe-test.ts b/src/subscription/__tests__/subscribe-test.ts index dcb02e042cb..85d6400a3df 100644 --- a/src/subscription/__tests__/subscribe-test.ts +++ b/src/subscription/__tests__/subscribe-test.ts @@ -313,7 +313,7 @@ describe('Subscription Initialization Phase', () => { }), }); - // TODO ts-expect-error (schema must not be null) + // @ts-expect-error (schema must not be null) (await expectPromise(subscribe({ schema: null, document }))).toRejectWith( 'Expected null to be a GraphQL schema.', ); @@ -323,7 +323,7 @@ describe('Subscription Initialization Phase', () => { 'Expected undefined to be a GraphQL schema.', ); - // TODO ts-expect-error (document must not be null) + // @ts-expect-error (document must not be null) (await expectPromise(subscribe({ schema, document: null }))).toRejectWith( 'Must provide document.', ); diff --git a/src/subscription/mapAsyncIterator.ts b/src/subscription/mapAsyncIterator.ts index 55fc3b94993..3ea9ea87450 100644 --- a/src/subscription/mapAsyncIterator.ts +++ b/src/subscription/mapAsyncIterator.ts @@ -18,7 +18,6 @@ export function mapAsyncIterator( } try { - // @ts-expect-error FIXME: TS Conversion return { value: await callback(result.value), done: false }; } catch (error) { // istanbul ignore else (FIXME: add test case) diff --git a/src/type/__tests__/definition-test.ts b/src/type/__tests__/definition-test.ts index 6011daaef9d..1cf4e4f397f 100644 --- a/src/type/__tests__/definition-test.ts +++ b/src/type/__tests__/definition-test.ts @@ -333,7 +333,7 @@ describe('Type System: Objects', () => { const objType = new GraphQLObjectType({ name: 'SomeObject', fields: { - // TODO ts-expect-error (must not be undefined) + // @ts-expect-error (must not be undefined) f: undefined, }, }); @@ -697,7 +697,7 @@ describe('Type System: Enums', () => { () => new GraphQLEnumType({ name: 'SomeEnum', - // TODO ts-expect-error (must not be null) + // @ts-expect-error (must not be null) values: { FOO: null }, }), ).to.throw( @@ -843,9 +843,9 @@ describe('Type System: List', () => { expectList(String).to.throw( 'Expected [function String] to be a GraphQL type.', ); - // TODO ts-expect-error (must provide type) + // @ts-expect-error (must provide type) expectList(null).to.throw('Expected null to be a GraphQL type.'); - // TODO ts-expect-error (must provide type) + // @ts-expect-error (must provide type) expectList(undefined).to.throw('Expected undefined to be a GraphQL type.'); }); }); @@ -876,11 +876,11 @@ describe('Type System: Non-Null', () => { expectNonNull(String).to.throw( 'Expected [function String] to be a GraphQL nullable type.', ); - // TODO ts-expect-error (must provide type) + // @ts-expect-error (must provide type) expectNonNull(null).to.throw( 'Expected null to be a GraphQL nullable type.', ); - // TODO ts-expect-error (must provide type) + // @ts-expect-error (must provide type) expectNonNull(undefined).to.throw( 'Expected undefined to be a GraphQL nullable type.', ); diff --git a/src/type/__tests__/validation-test.ts b/src/type/__tests__/validation-test.ts index 61d43a60303..6d8ef8f7895 100644 --- a/src/type/__tests__/validation-test.ts +++ b/src/type/__tests__/validation-test.ts @@ -1036,7 +1036,7 @@ describe('Type System: Object fields must have output types', () => { } it('rejects an empty Object field type', () => { - // TODO ts-expect-error (type field must not be undefined) + // @ts-expect-error (type field must not be undefined) const schema = schemaWithObjectField({ type: undefined }); expect(validateSchema(schema)).to.deep.equal([ { @@ -1098,7 +1098,7 @@ describe('Type System: Objects can only implement unique interfaces', () => { const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'BadObject', - // TODO ts-expect-error (interfaces must not contain undefined) + // @ts-expect-error (interfaces must not contain undefined) interfaces: [undefined], fields: { f: { type: GraphQLString } }, }), @@ -1357,7 +1357,7 @@ describe('Type System: Interface fields must have output types', () => { } it('rejects an empty Interface field type', () => { - // TODO ts-expect-error (type field must not be undefined) + // @ts-expect-error (type field must not be undefined) const schema = schemaWithInterfaceField({ type: undefined }); expect(validateSchema(schema)).to.deep.equal([ { @@ -1493,7 +1493,7 @@ describe('Type System: Arguments must have input types', () => { } it('rejects an empty field arg type', () => { - // TODO ts-expect-error (type field must not be undefined) + // @ts-expect-error (type field must not be undefined) const schema = schemaWithArg({ type: undefined }); expect(validateSchema(schema)).to.deep.equal([ { @@ -1631,7 +1631,7 @@ describe('Type System: Input Object fields must have input types', () => { } it('rejects an empty input field type', () => { - // TODO ts-expect-error (type field must not be undefined) + // @ts-expect-error (type field must not be undefined) const schema = schemaWithInputField({ type: undefined }); expect(validateSchema(schema)).to.deep.equal([ { diff --git a/src/utilities/__tests__/buildASTSchema-test.ts b/src/utilities/__tests__/buildASTSchema-test.ts index 69d09c6705f..5cc4121defa 100644 --- a/src/utilities/__tests__/buildASTSchema-test.ts +++ b/src/utilities/__tests__/buildASTSchema-test.ts @@ -1095,7 +1095,7 @@ describe('Schema Builder', () => { }); it('Rejects invalid AST', () => { - // TODO ts-expect-error (First parameter expected to be DocumentNode) + // @ts-expect-error (First parameter expected to be DocumentNode) expect(() => buildASTSchema(null)).to.throw( 'Must provide valid Document AST', ); diff --git a/src/utilities/__tests__/buildClientSchema-test.ts b/src/utilities/__tests__/buildClientSchema-test.ts index aa516bf7a17..d65f69b54ad 100644 --- a/src/utilities/__tests__/buildClientSchema-test.ts +++ b/src/utilities/__tests__/buildClientSchema-test.ts @@ -629,7 +629,7 @@ describe('Type System: build schema from introspection', () => { `); it('throws when introspection is missing __schema property', () => { - // TODO ts-expect-error (First parameter expected to be introspection results) + // @ts-expect-error (First parameter expected to be introspection results) expect(() => buildClientSchema(null)).to.throw( 'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: null.', ); diff --git a/src/utilities/__tests__/extendSchema-test.ts b/src/utilities/__tests__/extendSchema-test.ts index d0d51ed5052..022d6a58130 100644 --- a/src/utilities/__tests__/extendSchema-test.ts +++ b/src/utilities/__tests__/extendSchema-test.ts @@ -1143,7 +1143,7 @@ describe('extendSchema', () => { it('Rejects invalid AST', () => { const schema = new GraphQLSchema({}); - // TODO ts-expect-error (Second argument expects DocumentNode) + // @ts-expect-error (Second argument expects DocumentNode) expect(() => extendSchema(schema, null)).to.throw( 'Must provide valid Document AST', ); diff --git a/src/utilities/extendSchema.ts b/src/utilities/extendSchema.ts index 5ad15835973..7b82e2ce397 100644 --- a/src/utilities/extendSchema.ts +++ b/src/utilities/extendSchema.ts @@ -406,7 +406,7 @@ export function extendSchemaImpl( // Note: While this could make early assertions to get the correctly // typed values below, that would throw immediately while type system // validation with validateSchema() will produce more actionable results. - // TODO ts-expect-error + // @ts-expect-error opTypes[operationType.operation] = getNamedType(operationType.type); } } diff --git a/src/validation/__tests__/validation-test.ts b/src/validation/__tests__/validation-test.ts index 42860051fc4..ed68d68788a 100644 --- a/src/validation/__tests__/validation-test.ts +++ b/src/validation/__tests__/validation-test.ts @@ -16,7 +16,7 @@ import { testSchema } from './harness'; describe('Validate: Supports full validation', () => { it('rejects invalid documents', () => { - // TODO ts-expect-error (expects a DocumentNode as a second parameter) + // @ts-expect-error (expects a DocumentNode as a second parameter) expect(() => validate(testSchema, null)).to.throw('Must provide document.'); }); diff --git a/tsconfig.json b/tsconfig.json index d160d317efa..c76ea4574fc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,10 +4,7 @@ "module": "commonjs", "lib": ["es2019", "es2020.promise", "es2020.bigint", "es2020.string"], "target": "es2019", - "noImplicitAny": false, - "noImplicitThis": false, - "strictNullChecks": false, - "strictFunctionTypes": true, + "strict": true, "noEmit": true, "forceConsistentCasingInFileNames": true }