graphql-fields-list
graphql-fields-list copied to clipboard
Error on tsc compilation
Hi,
I'm getting this error when trying to compile a project that I added graphql-fields-list.
node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts:509:52 - error TS2379: Argument of type '{ fragments: ObjMap<FragmentDefinitionNode>; vars: { [variable: string]: unknown; }; withVars: boolean | undefined; }' is not assignable to parameter of type 'TraverseOptions' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'withVars' are incompatible.
Type 'boolean | undefined' is not assignable to type 'boolean'.
Type 'undefined' is not assignable to type 'boolean'.
509 const tree = traverse(getNodes(fieldNode), {}, {
~
510 fragments: info.fragments,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
512 withVars: withDirectives,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
513 },
~~~~~~~~~
It's the only lib giving problems.
Can you fix?
Thanks.
Related to having this https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes enabled.
@Mikhus
A few other errors related to another typescript setting. "verbatimModuleSyntax": true
node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts:19:5 - error TS1484: 'ArgumentNode' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
19 ArgumentNode,
~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts:20:5 - error TS1484: 'DirectiveNode' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
20 DirectiveNode,
~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts:21:5 - error TS1484: 'SelectionNode' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
21 SelectionNode,
~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts:22:5 - error TS1484: 'FragmentDefinitionNode' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
22 FragmentDefinitionNode,
~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts:23:5 - error TS1484: 'GraphQLResolveInfo' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
23 GraphQLResolveInfo,
~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts:24:5 - error TS1484: 'FieldNode' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
24 FieldNode,
~~~~~~~~~
These might be fixable with import { type ArgumentNode,
Related to having this https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes enabled.
This one should not be an issue if you add the https://www.typescriptlang.org/tsconfig/#skipLibCheck, which is something you should always do anyway (no point in checking the types of shipped libs). Are you using it?
Regarding the second one, since it is a https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax, it doesn't respect skipLibChecks and still checks them.
Thanks for opening the PR and fixing it.
I am wondering if it might be better to exclude the fix for exactOptionalPropertyTypes and focus only on verbatimModuleSyntax?
@dougg0k adding your fix, shows new compliation issues with verbatimModuleSyntax on.
│ ../../node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts:498:1 - error TS1287: A top-level 'export' modifier cannot be used on value declar
│ ations in a CommonJS module when 'verbatimModuleSyntax' is enabled.
│
│ 498 export function fieldsMap(
│ ~~~~~~
│
│ ../../node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts:530:1 - error TS1287: A top-level 'export' modifier cannot be used on value declar
│ ations in a CommonJS module when 'verbatimModuleSyntax' is enabled.
│
│ 530 export function fieldsList(
│ ~~~~~~
│
│ ../../node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts:562:1 - error TS1287: A top-level 'export' modifier cannot be used on value declar
│ ations in a CommonJS module when 'verbatimModuleSyntax' is enabled.
│
│ 562 export function fieldsProjection(
│ ~~~~~~
│
│
│ Found 3 errors in the same file, starting at: ../../node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts:498
Related to having this https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes enabled. @Mikhus
This one should not be an issue if you add the https://www.typescriptlang.org/tsconfig/#skipLibCheck, which is something you should always do anyway (no point in checking the types of shipped libs). Are you using it?
Regarding the second one, since it is a https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax, it doesn't respect
skipLibChecksand still checks them. Thanks for opening the PR and fixing it.I am wondering if it might be better to exclude the fix for exactOptionalPropertyTypes and focus only on verbatimModuleSyntax?
No, I'm not using it.
It should result in the same as it already was, because the variable being passed to it were type | undefined.
This lib (from many) were the only one with type problems. So, it's something.
Edit:
https://tkdodo.eu/blog/optional-vs-undefined Both have different intents, so it's a valid thing to have.
Edit2:
I was mistaken, "skipLibCheck": true, were set. Even then, the type error appeared.
@fox1t @dougg0k I'm also getting a similar error:
$ tsc --noEmit --project tsconfig.app.json
../../../node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts(294,27): error TS2538: Type 'undefined' cannot be used as an index type.
../../../node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts(295,26): error TS2538: Type 'undefined' cannot be used as an index type.
../../../node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts(299,33): error TS2538: Type 'undefined' cannot be used as an index type.
../../../node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts(318,9): error TS2322: Type 'SkipValue | undefined' is not assignable to type 'SkipValue'.
Type 'undefined' is not assignable to type 'SkipValue'.
../../../node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts(331,13): error TS2322: Type 'SkipValue | undefined' is not assignable to type 'SkipValue'.
Type 'undefined' is not assignable to type 'SkipValue'.
../../../node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts(390,17): error TS2345: Argument of type 'MapResultKey | undefined' is not assignable to parameter of type 'MapResultKey'.
Type 'undefined' is not assignable to type 'MapResultKey'.
../../../node_modules/.pnpm/[email protected]/node_modules/graphql-fields-list/index.ts(593,17): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
"skipLibCheck": true is set in my tsconfig, and what I did to solve this issue within my repo was to patch [email protected] to add the following line to the package.json:
"types": "index.d.ts",
I've created this PR with the fix: https://github.com/Mikhus/graphql-fields-list/pull/45.
These changes fixed all the issues with a patch, in a project. https://github.com/Mikhus/graphql-fields-list/pull/44