Skip to content

Commit d8aa07f

Browse files
eddeee888claude
andauthored
chore: enable strict: true in root tsconfig (#4683) (#10985)
* test: reproduce #4683 — enable `strict: true` in root tsconfig (failing) Replace the individual strictness flags (`alwaysStrict`, `noImplicitThis`, `noImplicitAny: false`, `strictNullChecks: false`) with `strict: true`. `tsc --noEmit` now reports 351 type errors across packages/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016PjJDfAYR1JPdgiQRvvZZy eddeee888:oss:issue-verify * chore: add changeset for declaration changes from strict tsconfig (#4683) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: satisfy strict mode with graphql 15 typings (#4683) graphql 15 types Maybe<T> as T | null | undefined, so the CI matrix's graphql 15 build hits three strict errors that 16/17 don't: - getPossibleTypes accepts null, which schema.getType() returns on 15 - includeIntrospectionTypesDefinitions skips getNamedType when the field type is missing - graphql-modules preset checks schemaAst.extensions before reading sources Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5078faf commit d8aa07f

5 files changed

Lines changed: 29 additions & 8 deletions

File tree

‎.changeset/strict-root-tsconfig.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@graphql-codegen/cli': patch
3+
'@graphql-codegen/visitor-plugin-common': patch
4+
'@graphql-codegen/typescript': patch
5+
'@graphql-codegen/client-preset': patch
6+
'@graphql-codegen/testing': patch
7+
'@graphql-codegen/graphql-modules-preset': patch
8+
---
9+
10+
Build with `strict: true`, which changes these emitted type declarations:
11+
12+
- `@graphql-codegen/cli`: `mkdirp` returns `Promise<string | undefined>`, and the `require` (`-r`) CLI option's `default` is typed `never[]` instead of `any[]`.
13+
- `@graphql-codegen/visitor-plugin-common`: `BaseResolversVisitor` and `BaseTypesVisitor` `SchemaDefinition()`/`SchemaExtension()` return `null` instead of `any`.
14+
- `@graphql-codegen/visitor-plugin-common`: `BaseSelectionSetProcessor.typeCache` is keyed by `Location | undefined`.
15+
- `@graphql-codegen/visitor-plugin-common`: `SelectionSetToObject.buildSelectionSet` returns `typeInfo` as `{ name: string; type: string } | null`.
16+
- `@graphql-codegen/visitor-plugin-common`: `getPossibleTypes` accepts `null` as the type, which graphql 15's `schema.getType()` can return.
17+
- `@graphql-codegen/visitor-plugin-common`: `removeDescription` returns nodes with `description: undefined` instead of `any`.
18+
- `@graphql-codegen/typescript`: `TsIntrospectionVisitor`'s constructor takes `pluginConfig` as `TypeScriptPluginConfig | undefined`, `DirectiveDefinition()` returns `null` and `ObjectTypeDefinition()` returns `string | null`.
19+
- `@graphql-codegen/client-preset`: the babel preset accepts `options` as `ClientBabelPresetOptions | null | undefined`.
20+
- `@graphql-codegen/testing`: `mockGraphQLServer` returns `nock.Scope | null`.
21+
- `@graphql-codegen/graphql-modules-preset`: a schema without `extensions` (graphql 15) throws the "requires to use GraphQL SDL" error instead of a `TypeError`.
22+
23+
Generated output is unchanged.

‎packages/plugins/other/visitor-plugin-common/src/utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ export function separateSelectionSet(selections: ReadonlyArray<SelectionNode>):
512512

513513
export function getPossibleTypes(
514514
schema: GraphQLSchema,
515-
type: GraphQLType | undefined,
515+
type: GraphQLType | null | undefined,
516516
): GraphQLObjectType[] {
517517
if (isListType(type) || isNonNullType(type)) {
518518
return getPossibleTypes(schema, type.ofType);

‎packages/plugins/typescript/typescript/src/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export function includeIntrospectionTypesDefinitions(
6363
const usedTypes: GraphQLNamedType[] = [];
6464
const documentsVisitor = visitWithTypeInfo(typeInfo, {
6565
Field() {
66-
const type = getNamedType(typeInfo.getType());
66+
const fieldType = typeInfo.getType();
67+
const type = fieldType ? getNamedType(fieldType) : undefined;
6768

6869
if (type && isIntrospectionType(type) && !usedTypes.includes(type)) {
6970
usedTypes.push(type);

‎packages/presets/graphql-modules/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const preset: Types.OutputPreset<ModulesConfig> = {
2323
);
2424
}
2525

26-
if (!options.schemaAst?.extensions.sources) {
26+
if (!options.schemaAst?.extensions?.sources) {
2727
throw new Error(`Preset "graphql-modules" requires to use GraphQL SDL`);
2828
}
2929

‎tsconfig.json‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"emitDecoratorMetadata": true,
1616
"sourceMap": true,
1717
"declaration": true,
18-
"noImplicitThis": true,
19-
"alwaysStrict": true,
18+
"strict": true,
2019
"noImplicitReturns": true,
2120
"noUnusedLocals": true,
2221
"resolveJsonModule": true,
@@ -52,9 +51,7 @@
5251
"@graphql-codegen/plugin-helpers": ["packages/utils/plugins-helpers/src/index.ts"]
5352
},
5453
"ignoreDeprecations": "6.0",
55-
"types": ["node"],
56-
"noImplicitAny": false,
57-
"strictNullChecks": false
54+
"types": ["node"]
5855
},
5956
"include": ["packages"],
6057
"exclude": [

0 commit comments

Comments
 (0)