Skip to content

Type 'undefined' cannot be used as an index type. #38

@SimonCockx

Description

@SimonCockx

I'm getting 8 errors when loading this package:

node_modules/graphql-fields-list/index.ts:292:27 - error TS2538: Type 'undefined' cannot be used as an index type.

292             if (!propTree[prop]) {
                              ~~~~

node_modules/graphql-fields-list/index.ts:293:26 - error TS2538: Type 'undefined' cannot be used as an index type.

293                 propTree[prop] = i === s - 1 || all ? true : {};
                             ~~~~

node_modules/graphql-fields-list/index.ts:297:33 - error TS2538: Type 'undefined' cannot be used as an index type.

297             propTree = propTree[prop] as SkipTree;
                                    ~~~~

node_modules/graphql-fields-list/index.ts:316:9 - error TS2322: Type 'SkipValue | undefined' is not assignable to type 'SkipValue'.
  Type 'undefined' is not assignable to type 'SkipValue'.

316         return (skip as SkipTree)[node];
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/graphql-fields-list/index.ts:327:13 - error TS2322: Type 'SkipValue | undefined' is not assignable to type 'SkipValue'.

327             nodeTree = (skip as SkipTree)[pattern];
                ~~~~~~~~

node_modules/graphql-fields-list/index.ts:371:31 - error TS2345: Argument of type 'FragmentDefinitionNode | undefined' is not assignable to parameter of type 'FragmentDefinitionNode | SelectionNode'.
  Type 'undefined' is not assignable to type 'FragmentDefinitionNode | SelectionNode'.

371             traverse(getNodes(opts.fragments[name]), root, opts, skip);
                                  ~~~~~~~~~~~~~~~~~~~~

node_modules/graphql-fields-list/index.ts:386:17 - error TS2345: Argument of type 'MapResultKey | undefined' is not assignable to parameter of type 'MapResultKey'.
  Type 'undefined' is not assignable to type 'MapResultKey'.

386                 (root as MapResult)[name],
                    ~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/graphql-fields-list/index.ts:587:17 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.

587                 dotName = transform[dotName];

This package seemed promising, but I'm not sure how I can use it if I can't import it without these errors.
Might be relevant to show my config:

{
   "$schema": "https://json.schemastore.org/tsconfig", // For code completion and type checking inside this file.
   "include": ["src/**/*", "test/**/*"],
   "exclude": ["node_modules", "dist"],
 
   "compilerOptions": {
     "target": "ES2017", // Specify ECMAScript target version: 'es3' (default), 'es5', 'es2015', 'es2016', 'es2017','es2018' or 'esnext'.
     "module": "commonjs", // Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'.
     "lib": ["DOM", "DOM.Iterable", "ESNext"], // Specify library files to be included in the compilation.
     "outDir": "./dist", // Redirect output structure to the directory.
 
     "strict": true, // Enable all strict type-checking options.
     "useUnknownInCatchVariables": true, // Type catch variables as 'unknown' by default.
     "alwaysStrict": true, // Parse in strict mode and emit "use strict" for each source file.
     "exactOptionalPropertyTypes": false, // Disallow assigning 'undefined' to optional properties.
     "noUncheckedIndexedAccess": true, // Add 'undefined' to the type of index signatures.
 
     "useDefineForClassFields": false,
     "experimentalDecorators": true, // Enables experimental support for ES7 decorators.
 
     "forceConsistentCasingInFileNames": true, // Disallow inconsistently-cased references to the same file.
     "noUnusedLocals": true, // Report errors on unused locals.
     "noUnusedParameters": true, // Report errors on unused parameters.
     "noImplicitOverride": true, // Force explicit 'override' keyword.
     "noImplicitReturns": true, // Report error when not all code paths in function return a value.
     "noFallthroughCasesInSwitch": true, // Report errors for fallthrough cases in switch statement.
     "noPropertyAccessFromIndexSignature": true, // Force consistency in dot operator versus indexing.
 
     "moduleResolution": "node", // Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6).
     "baseUrl": "./", // Base directory to resolve non-absolute module names.
     "types": ["validator", "jest", "node"], // Type declaration files to be included in compilation.
     "esModuleInterop": true, // Emit '__importStar' and '__importDefault' helpers for runtime babel ecosystem compatibility and enable '--allowSyntheticDefaultImports' for typesystem compatibility.
     "resolveJsonModule": true, // Include modules imported with '.json' extension.

     "incremental": true, // Enable incremental compilation by reading/writing information from prior compilations to a file on disk.

     "emitDecoratorMetadata": true, // Enables experimental support for emitting type metadata for decorators.
 
     "sourceMap": true // Generates corresponding '.map' file.
   },
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions