uport-project / ethr-did

Create ethr DIDs
Apache License 2.0
263 stars 54 forks source link

[BUG] Cannot use `MetaSignature` namespace as type #110

Closed francesco-plt closed 1 year ago

francesco-plt commented 1 year ago

Current Behavior

The library cannot be used at its current state. If I try to import it in any typescript project, I get the following error: Cannot use MetaSignature namespace as type At node_modules/ethr-did/lib/index.d.ts. Every occurrence of the MetaSignature keywork is marked with the error above. This results in typescript failing build and as a consequence the whole library is unusable.

Expected Behavior

Just running the code in the README should work without any error.

Steps to Reproduce

The following code snippet is enough to produce the error:

import { EthrDID } from 'ethr-did'
// some code
const stockVc = await createVerifiableCredentialJwt(
    payload,
    new EthrDID({
      identifier: issuer.getAddress(),
      privateKey: issuer.getPrivateKey()
    }) as Issuer
  )
// some code
mirceanis commented 1 year ago

I was not able to reproduce this. Here is my attempt: https://github.com/mirceanis/ts-ethr-did Please link to a project where this manifests if the project I linked to doesn't help.

francesco-plt commented 1 year ago

I was not able to reproduce this. Here is my attempt: https://github.com/mirceanis/ts-ethr-did Please link to a project where this manifests if the project I linked to doesn't help.

What I did:

$ git clone https://github.com/mirceanis/ts-ethr-did
$ cd ts-ethr-did
$ tsc src/ethr-110.ts

Result:

node_modules/ethr-did-resolver/lib/index.d.ts:4:48 - error TS2732: Cannot find module './config/EthereumDIDRegistry.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.

4 import { default as EthereumDIDRegistry } from './config/EthereumDIDRegistry.json';
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/multiformats/types/src/cid.d.ts:160:85 - error TS2344: Type 'Prefix' does not satisfy the constraint 'string'.

160 export type MultibaseEncoder<Prefix> = import('./bases/interface').MultibaseEncoder<Prefix>;
                                                                                        ~~~~~~

  node_modules/multiformats/types/src/cid.d.ts:160:30
    160 export type MultibaseEncoder<Prefix> = import('./bases/interface').MultibaseEncoder<Prefix>;
                                     ~~~~~~
    This type parameter might need an `extends string` constraint.

node_modules/multiformats/types/src/cid.d.ts:161:85 - error TS2344: Type 'Prefix' does not satisfy the constraint 'string'.

161 export type MultibaseDecoder<Prefix> = import('./bases/interface').MultibaseDecoder<Prefix>;
                                                                                        ~~~~~~

  node_modules/multiformats/types/src/cid.d.ts:161:30
    161 export type MultibaseDecoder<Prefix> = import('./bases/interface').MultibaseDecoder<Prefix>;
                                     ~~~~~~
    This type parameter might need an `extends string` constraint.

src/ethr-110.ts:6:17 - error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher.

6 const stockVc = await createVerifiableCredentialJwt(
                  ~~~~~

Found 4 errors in 3 files.

Errors  Files
     1  node_modules/ethr-did-resolver/lib/index.d.ts:4
     2  node_modules/multiformats/types/src/cid.d.ts:160
     1  src/ethr-110.ts:6

Looks like a problem with typescript configuration

mirceanis commented 1 year ago

Did you also try the instructions I left in the readme of that project?

francesco-plt commented 1 year ago

Reconfiguring the project with a minimal tsconfig.json fixed the issue.