Skip to content

tsc spitting out about 40 type errors #60

@Mischala

Description

@Mischala

tsc -p tsconfig.json is emitting a bunch of type errors.
Seems they are all to do with Native CryptoKey and CryptoKeyPair types being incompatible with those defined in src/key.ts

Because we are extending the types defined in webcrypto-core, and the non-native key types are defined in Liner, the implementing classes expect to accept and return native CryptoKey and CryptoKeyPair types.

possible solution, move the definitions in src/key.ts and change all the return values?

  Types of property 'generateKey' are incompatible.
    Type '(algorithm: AesKeyGenParams, extractable: boolean, keyUsages: string[]) => PromiseLike<CryptoKeyPair | CryptoKey>' is not assignable to type '(algorithm: Algorithm, extractable: boolean, keyUsages: string[]) => PromiseLike<CryptoKey | CryptoKeyPair>'.
      Type 'PromiseLike<CryptoKeyPair | CryptoKey>' is not assignable to type 'PromiseLike<CryptoKey | CryptoKeyPair>'.
        Type 'CryptoKeyPair | CryptoKey' is not assignable to type 'CryptoKey | CryptoKeyPair'.
          Type 'CryptoKeyPair' is not assignable to type 'CryptoKey | CryptoKeyPair'.
            Type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKeyPair' is not assignable to type 'CryptoKeyPair'.
              Types of property 'privateKey' are incompatible.
                Type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey' is not assignable to type 'CryptoKey'.
src/ec/crypto.ts(63,14): error TS2417: Class static side 'typeof EcCrypto' incorrectly extends base class static side 'typeof BaseCrypto'.
  Types of property 'generateKey' are incompatible.
    Type '(algorithm: Algorithm, extractable: boolean, keyUsage: string[]) => Promise<{ privateKey: CryptoKey; publicKey: CryptoKey; }>' is not assignable to type '(algorithm: Algorithm, extractable: boolean, keyUsages: string[]) => PromiseLike<CryptoKey | CryptoKeyPair>'.
src/key.ts(1,18): error TS2430: Interface 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKeyPair' incorrectly extends interface 'CryptoKeyPair'.
  Types of property 'privateKey' are incompatible.
    Type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey' is not assignable to type 'CryptoKey'.
      Types of property 'type' are incompatible.
        Type 'string' is not assignable to type 'KeyType'.
src/key.ts(17,12): error TS2416: Property 'type' in type 'CryptoKey' is not assignable to the same property in base type 'CryptoKey'.
  Type 'string' is not assignable to type 'KeyType'.
src/key.ts(18,12): error TS2416: Property 'usages' in type 'CryptoKey' is not assignable to the same property in base type 'CryptoKey'.
  Type 'string[]' is not assignable to type 'KeyUsage[]'.
    Type 'string' is not assignable to type 'KeyUsage'.
src/rsa/crypto.ts(22,14): error TS2417: Class static side 'typeof RsaCrypto' incorrectly extends base class static side 'typeof BaseCrypto'.
  Types of property 'generateKey' are incompatible.
    Type '(algorithm: RsaKeyGenParams, extractable: boolean, keyUsage: string[]) => PromiseLike<CryptoKeyPair>' is not assignable to type '(algorithm: Algorithm, extractable: boolean, keyUsages: string[]) => PromiseLike<CryptoKey | CryptoKeyPair>'.
src/subtle.ts(134,25): error TS2322: Type 'typeof AesCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(138,25): error TS2322: Type 'typeof EcCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(143,25): error TS2322: Type 'typeof RsaCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(180,12): error TS2416: Property 'sign' in type 'SubtleCrypto' is not assignable to the same property in base type 'SubtleCrypto'.
  Type '(algorithm: string | EcdsaParams | RsaPssParams | AesCmacParams, key: import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey, data: BufferSource) => PromiseLike<ArrayBuffer>' is not assignable to type '(algorithm: string | EcdsaParams | RsaPssParams | AesCmacParams, key: CryptoKey, data: BufferSource) => PromiseLike<ArrayBuffer>'.
    Types of parameters 'key' and 'key' are incompatible.
      Type 'CryptoKey' is not assignable to type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey'.
        Property 'key' is missing in type 'CryptoKey'.
src/subtle.ts(212,25): error TS2322: Type 'typeof EcCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(216,25): error TS2322: Type 'typeof RsaCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(226,12): error TS2416: Property 'verify' in type 'SubtleCrypto' is not assignable to the same property in base type 'SubtleCrypto'.
  Type '(algorithm: string | EcdsaParams | RsaPssParams | AesCmacParams, key: import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey, signature: BufferSource, data: BufferSource) => PromiseLike<...>' is not assignable to type '(algorithm: string | EcdsaParams | RsaPssParams | AesCmacParams, key: CryptoKey, signature: BufferSource, data: BufferSource) => PromiseLike<boolean>'.
    Types of parameters 'key' and 'key' are incompatible.
      Type 'CryptoKey' is not assignable to type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey'.
src/subtle.ts(259,25): error TS2322: Type 'typeof EcCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(263,25): error TS2322: Type 'typeof RsaCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(273,12): error TS2416: Property 'deriveBits' in type 'SubtleCrypto' is not assignable to the same property in base type 'SubtleCrypto'.
  Type '(algorithm: string | Algorithm, baseKey: CryptoKey, length: number) => PromiseLike<ArrayBuffer>' is not assignable to type '(algorithm: string | EcdhKeyDeriveParams | Pbkdf2Params | ConcatParams | DhKeyDeriveParams | HkdfCtrParams, baseKey: CryptoKey, length: number) => PromiseLike<ArrayBuffer>'.
    Types of parameters 'baseKey' and 'baseKey' are incompatible.
      Type 'CryptoKey' is not assignable to type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey'.
src/subtle.ts(300,25): error TS2322: Type 'typeof EcCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(305,46): error TS2345: Argument of type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey' is not assignable to parameter of type 'CryptoKey'.
src/subtle.ts(309,12): error TS2416: Property 'deriveKey' in type 'SubtleCrypto' is not assignable to the same property in base type 'SubtleCrypto'.
  Type '(algorithm: string | Algorithm, baseKey: CryptoKey, derivedKeyType: string | Algorithm, extractable: boolean, keyUsages: string[]) => PromiseLike<CryptoKey>' is not assignable to type '(algorithm: string | EcdhKeyDeriveParams | Pbkdf2Params | ConcatParams | DhKeyDeriveParams | HkdfCtrParams, baseKey: CryptoKey, derivedKeyType: string | AesDerivedKeyParams | HmacImportParams | Pbkdf2Params | ConcatParams | HkdfCtrParams, extractable: boolean, keyUsages: string[]) => PromiseLike<...>'.
    Types of parameters 'baseKey' and 'baseKey' are incompatible.
      Type 'CryptoKey' is not assignable to type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey'.
src/subtle.ts(338,25): error TS2322: Type 'typeof EcCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(343,45): error TS2345: Argument of type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey' is not assignable to parameter of type 'CryptoKey'.
src/subtle.ts(347,12): error TS2416: Property 'encrypt' in type 'SubtleCrypto' is not assignable to the same property in base type 'SubtleCrypto'.
  Type '(algorithm: string | Algorithm, key: CryptoKey, data: BufferSource) => PromiseLike<ArrayBuffer>' is not assignable to type '(algorithm: string | AesCbcParams | AesCtrParams | AesGcmParams | RsaOaepParams | AesCfbParams | AesCmacParams, key: CryptoKey, data: BufferSource) => PromiseLike<ArrayBuffer>'.
    Types of parameters 'key' and 'key' are incompatible.
      Type 'CryptoKey' is not assignable to type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey'.
src/subtle.ts(386,25): error TS2322: Type 'typeof AesCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(389,25): error TS2322: Type 'typeof RsaCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(399,12): error TS2416: Property 'decrypt' in type 'SubtleCrypto' is not assignable to the same property in base type 'SubtleCrypto'.
  Type '(algorithm: string | Algorithm, key: CryptoKey, data: BufferSource) => PromiseLike<ArrayBuffer>' is not assignable to type '(algorithm: string | AesCbcParams | AesCtrParams | AesGcmParams | RsaOaepParams | AesCfbParams | AesCmacParams, key: CryptoKey, data: BufferSource) => PromiseLike<ArrayBuffer>'.
    Types of parameters 'key' and 'key' are incompatible.
      Type 'CryptoKey' is not assignable to type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey'.
src/subtle.ts(427,29): error TS2322: Type 'typeof AesCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(430,29): error TS2322: Type 'typeof RsaCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(435,47): error TS2345: Argument of type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey' is not assignable to parameter of type 'CryptoKey'.
src/subtle.ts(440,12): error TS2416: Property 'wrapKey' in type 'SubtleCrypto' is not assignable to the same property in base type 'SubtleCrypto'.
  Type '(format: string, key: import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey, wrappingKey: import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey, wrapAlgorithm: string | Algorithm) => PromiseLike<...>' is not assignable to type '(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: string | Algorithm) => PromiseLike<ArrayBuffer>'.
    Types of parameters 'key' and 'key' are incompatible.
      Type 'CryptoKey' is not assignable to type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey'.
src/subtle.ts(467,25): error TS2322: Type 'typeof AesCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(470,25): error TS2322: Type 'typeof RsaCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(475,46): error TS2345: Argument of type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey' is not assignable to parameter of type 'CryptoKey'.
src/subtle.ts(479,12): error TS2416: Property 'unwrapKey' in type 'SubtleCrypto' is not assignable to the same property in base type 'SubtleCrypto'.
  Type '(format: string, wrappedKey: BufferSource, unwrappingKey: import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey, unwrapAlgorithm: string | Algorithm, unwrappedKeyAlgorithm: string | Algorithm, extractable: boolean, keyUsages: string[]) => PromiseLike<...>' is not assignable to type '(format: string, wrappedKey: BufferSource, unwrappingKey: CryptoKey, unwrapAlgorithm: string | Algorithm, unwrappedKeyAlgorithm: string | Algorithm, extractable: boolean, keyUsages: string[]) => PromiseLike<...>'.
    Types of parameters 'unwrappingKey' and 'unwrappingKey' are incompatible.
      Type 'CryptoKey' is not assignable to type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey'.
src/subtle.ts(522,29): error TS2322: Type 'typeof AesCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(525,29): error TS2322: Type 'typeof RsaCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(530,63): error TS2345: Argument of type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey' is not assignable to parameter of type 'CryptoKey'.
src/subtle.ts(535,12): error TS2416: Property 'exportKey' in type 'SubtleCrypto' is not assignable to the same property in base type 'SubtleCrypto'.
  Type '(format: string, key: CryptoKey) => any' is not assignable to type '{ (format: "jwk", key: CryptoKey): PromiseLike<JsonWebKey>; (format: "raw" | "pkcs8" | "spki", key: CryptoKey): PromiseLike<ArrayBuffer>; (format: string, key: CryptoKey): PromiseLike<...>; }'.
    Types of parameters 'key' and 'key' are incompatible.
      Type 'CryptoKey' is not assignable to type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey'.
src/subtle.ts(571,25): error TS2322: Type 'typeof AesCrypto' is not assignable to type 'typeof BaseCrypto'.
  Types of property 'generateKey' are incompatible.
    Type '(algorithm: AesKeyGenParams, extractable: boolean, keyUsages: string[]) => PromiseLike<CryptoKeyPair | CryptoKey>' is not assignable to type '(algorithm: Algorithm, extractable: boolean, keyUsages: string[]) => PromiseLike<CryptoKey | CryptoKeyPair>'.
src/subtle.ts(575,25): error TS2322: Type 'typeof EcCrypto' is not assignable to type 'typeof BaseCrypto'.
  Types of property 'generateKey' are incompatible.
    Type '(algorithm: Algorithm, extractable: boolean, keyUsage: string[]) => Promise<{ privateKey: CryptoKey; publicKey: CryptoKey; }>' is not assignable to type '(algorithm: Algorithm, extractable: boolean, keyUsages: string[]) => PromiseLike<CryptoKey | CryptoKeyPair>'.
      Type 'Promise<{ privateKey: CryptoKey; publicKey: CryptoKey; }>' is not assignable to type 'PromiseLike<CryptoKey | CryptoKeyPair>'.
        Types of property 'then' are incompatible.
          Type '<TResult1 = { privateKey: CryptoKey; publicKey: CryptoKey; }, TResult2 = never>(onfulfilled?: ((value: { privateKey: CryptoKey; publicKey: CryptoKey; }) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | ... 1 more ... | undefined) => Promise<...>' is not assignable to type '<TResult1 = CryptoKey | CryptoKeyPair, TResult2 = never>(onfulfilled?: ((value: CryptoKey | CryptoKeyPair) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | null | undefined) => PromiseLike<...>'.
            Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
              Types of parameters 'value' and 'value' are incompatible.
                Type '{ privateKey: CryptoKey; publicKey: CryptoKey; }' is not assignable to type 'CryptoKey | CryptoKeyPair'.
                  Type '{ privateKey: CryptoKey; publicKey: CryptoKey; }' is not assignable to type 'CryptoKeyPair'.
                    Types of property 'privateKey' are incompatible.
                      Type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey' is not assignable to type 'CryptoKey'.
src/subtle.ts(580,25): error TS2322: Type 'typeof RsaCrypto' is not assignable to type 'typeof BaseCrypto'.
  Types of property 'generateKey' are incompatible.
    Type '(algorithm: RsaKeyGenParams, extractable: boolean, keyUsage: string[]) => PromiseLike<CryptoKeyPair>' is not assignable to type '(algorithm: Algorithm, extractable: boolean, keyUsages: string[]) => PromiseLike<CryptoKey | CryptoKeyPair>'.
      Type 'PromiseLike<CryptoKeyPair>' is not assignable to type 'PromiseLike<CryptoKey | CryptoKeyPair>'.
        Type 'CryptoKeyPair' is not assignable to type 'CryptoKey | CryptoKeyPair'.
          Type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKeyPair' is not assignable to type 'CryptoKeyPair'.
src/subtle.ts(585,48): error TS2345: Argument of type 'import("/home/mischa/repos/webcrypto-liner/src/key").CryptoKey' is not assignable to parameter of type 'CryptoKey'.
src/subtle.ts(643,25): error TS2322: Type 'typeof AesCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(647,25): error TS2322: Type 'typeof EcCrypto' is not assignable to type 'typeof BaseCrypto'.
src/subtle.ts(652,25): error TS2322: Type 'typeof RsaCrypto' is not assignable to type 'typeof BaseCrypto'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions