Working on a project, I encountered an issue with a third-party library written in Typescript 3.7. The outdated library depended on the 'lib' that contained an interface called DhImportKeyParams
. However, my current project uses Typescript 4.6 where this interface has been removed. As a result, when testing, I face the error "Cannot find name 'DhImportKeyParams'" due to the definition of the interface in the third-party library's ".d.ts" file:
export interface CryptoScheme {
genAlg: Pbkdf2Params | AesKeyGenParams | HmacKeyGenParams;
alg: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | any;
encrypt(key: CryptoKey, plaintext: string): PromiseLike<EncryptedObject>;
decrypt(key: CryptoKey, obj: EncryptedObject): PromiseLike<string>;
}
I attempted to redefine DhImportKeyParams
by creating a new interface in a separate file named typings.d.ts
:
declare interface DhImportKeyParams extends Algorithm {
generator: Uint8Array;
prime: Uint8Array;
}
Even after adding the reference to this file in the tsconfig.json
's typeRoots
, the error persisted when running tests using tsconfig.spec.json
. How can I properly define the missing interface so that Typescript can understand and compile the third-party library?