1- const usageInline = crypto . subtle . generateKey ( {
2- name : "AES-GCM" ,
3- length : 256 ,
4- } , true , [ 'encrypt' , 'decrypt' ] )
5-
6- const usageConst = crypto . subtle . generateKey ( {
7- name : "AES-GCM" ,
8- length : 256 ,
9- } , true , [ 'encrypt' , 'decrypt' ] as const )
10-
11- const keyUsage : ReadonlyArray < KeyUsage > = [ 'encrypt' , 'decrypt' ]
12- const usageAsReadonly = crypto . subtle . generateKey ( {
13- name : "AES-GCM" ,
14- length : 256 ,
15- } , true , keyUsage )
1+ function assertType < T > ( _x : T ) { }
2+
3+ const mockKey = { } as CryptoKey ;
4+
5+ assertType < Promise < JsonWebKey > > ( crypto . subtle . exportKey ( "jwk" , mockKey ) ) ;
6+ assertType < Promise < ArrayBuffer > > ( crypto . subtle . exportKey ( "pkcs8" , mockKey ) ) ;
7+ assertType < Promise < ArrayBuffer > > ( crypto . subtle . exportKey ( "raw" , mockKey ) ) ;
8+ assertType < Promise < ArrayBuffer > > ( crypto . subtle . exportKey ( "spki" , mockKey ) ) ;
9+
10+ assertType < Promise < ArrayBuffer | JsonWebKey > > (
11+ crypto . subtle
12+ . exportKey ( "" as KeyFormat , mockKey )
13+ . then ( ( ambiguousExportedKeyData ) =>
14+ ambiguousExportedKeyData instanceof ArrayBuffer
15+ ? ( ambiguousExportedKeyData satisfies ArrayBuffer )
16+ : ( ambiguousExportedKeyData satisfies JsonWebKey )
17+ )
18+ ) ;
19+
20+ const usageInline = crypto . subtle . generateKey (
21+ {
22+ name : "AES-GCM" ,
23+ length : 256 ,
24+ } ,
25+ true ,
26+ [ "encrypt" , "decrypt" ]
27+ ) ;
28+
29+ const usageConst = crypto . subtle . generateKey (
30+ {
31+ name : "AES-GCM" ,
32+ length : 256 ,
33+ } ,
34+ true ,
35+ [ "encrypt" , "decrypt" ] as const
36+ ) ;
37+
38+ const keyUsage : ReadonlyArray < KeyUsage > = [ "encrypt" , "decrypt" ] ;
39+ const usageAsReadonly = crypto . subtle . generateKey (
40+ {
41+ name : "AES-GCM" ,
42+ length : 256 ,
43+ } ,
44+ true ,
45+ keyUsage
46+ ) ;
0 commit comments