-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
Milestone
Description
Search Terms:
cryptokey algorithm
Code
function sign(key: CryptoKey, message: ArrayBuffer): Promise<ArrayBuffer> {
return crypto.subtle.sign(
key.algorithm,
key,
message,
);
}Expected behavior:
CryptoKey.algorithm is an appropriate way to pass the key algorithm to subtle methods such as sign and encrypt. However, the original definition of the type CryptoKey defines the type of algorithm as KeyAlgorithm which misses extra attributes that could be there.
Therefor the expected behavior is for the code to now have a type error and compile correctly. Maybe the correct type for CryptoKey should be
interface CryptoKey {
readonly algorithm: RsaKeyAlgorithm | EcKeyAlgorithm | AesKeyAlgorithm | HmacKeyAlgorithm | DhKeyAlgorithm;
readonly extractable: boolean;
readonly type: string;
readonly usages: string[];
}I am not sure how to fully test such a change, since modifying lib.es6.d.ts locally and running tsc produces the same message.
Actual behavior:
The following type error:
Argument of type 'KeyAlgorithm' is not assignable to parameter of type 'string | RsaPssParams | EcdsaParams | AesCmacParams'.
Type 'KeyAlgorithm' is not assignable to type 'AesCmacParams'.
Property 'length' is missing in type 'KeyAlgorithm'. (2345)
Playground Link: Playground link
Related Issues: Unknown
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this