Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Type 'K' cannot be used to index type #1828

Closed
1 task done
Spacylion opened this issue Feb 20, 2024 · 2 comments
Closed
1 task done

bug: Type 'K' cannot be used to index type #1828

Spacylion opened this issue Feb 20, 2024 · 2 comments

Comments

@Spacylion
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

2.7.11

Current Behavior

When attempting to compile TypeScript files with viem version 2.7.11, a series of errors are encountered, preventing successful compilation.

Expected Behavior

I expected the TypeScript files to compile successfully without encountering any errors.

Steps To Reproduce

  1. Clone the following GitHub repository: viem_test
  2. Install dependencies by running npm install.
  3. Attempt to compile TypeScript files using the command tsc -p tsconfig.json

Full explanation:

Reproducing TypeScript Compilation Error with viem

This guide will walk you through the steps to reproduce the TypeScript compilation error when using the viem library.

Prerequisites

Before starting, ensure that you have Node.js and npm installed on your system.

Steps

  1. Create a new directory and navigate into it:

    mkdir VIEM_TEST
    cd VIEM_TEST
  2. Initialize a new npm project:

    npm init -y
  3. Install the viem library:

    npm install [email protected]
  4. Create a TypeScript file named index.ts with the following content:

    // index.ts
    import { createPublicClient } from "viem/_types/clients/createPublicClient";
    import { createWalletClient } from "viem/_types/clients/createWalletClient";
    
    
    function greet(name: string): string {
        console.log( createPublicClient);
        console.log(  createWalletClient);
        
        return `Hello, ${name}!`;
        
    }
    
    const personName: string = "John";
    console.log(greet(personName));
  5. Create a tsconfig.json file with the following configuration:

    {
        "compilerOptions": {
            "forceConsistentCasingInFileNames": true,
            "newLine": "lf",
            "noFallthroughCasesInSwitch": true,
            "noImplicitReturns": true,
            "noUncheckedIndexedAccess": true,
            "noUnusedParameters": true,
            "strict": true,
            "target": "ES2019",
            "moduleResolution": "node",
            "esModuleInterop": true
        },
        "include": [
            "src/**/*.ts"
        ]
    }
    
  6. Run the TypeScript compiler:

    tsc --build

You should see the following error:

errors.txt

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

https://github.com/Spacylion/viem_test

Anything else?

The compilation errors occur primarily in the
node_modules/viem/_types/utils/formatters/transaction.d.ts
and
node_modules/viem/_types/utils/formatters/transactionRequest.d.ts
files.

These errors hinder the compilation process and need to be addressed for smooth integration with viem version 2.7.11.
errors.txt

@Spacylion Spacylion changed the title bug: TypeScript compilation errors bug: Type 'K' cannot be used to index type Feb 20, 2024
@jxom
Copy link
Member

jxom commented Feb 20, 2024

Please enable skipLibCheck

@jxom jxom closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2024
Copy link
Contributor

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Viem version. If you have any questions or comments you can create a new discussion thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants