Skip to content

SubtleCrypto interface type definitions not valid #7761

@samuelhorwitz

Description

@samuelhorwitz

TypeScript Version:

1.8.9

Code

Example 1

crypto.subtle.sign(
    {
        name: 'ECDSA',
        hash: {
            name: 'SHA-256'
        }
    },
    privateKey,
    arrayBuffer
);

Expected behavior:
It is acceptable for the first argument to be an object. Should compile.

Actual behavior:
Error TS2345: Argument of type '{ name: string; hash: { name: string; }; }' is not assignable to parameter of type 'string | Algorithm'. Object literal may only specify known properties, and 'hash' does not exist in type 'string | Algorithm'.

Example 2

crypto.subtle.generateKey(
    {
        name: 'ECDSA',
        namedCurve: 'P-256'
    },
    false,
    ['sign']
);

Expected behavior:
It is acceptable for the first argument to be an object. Should compile.

Actual behavior:
Error TS2345: Argument of type \'{ name: string; namedCurve: string; }\' is not assignable to parameter of type \'string | Algorithm\'.\n Object literal may only specify known properties, and \'namedCurve\' does not exist in type \'string | Algorithm\'.

Example 3

crypto.subtle.verify(
    {
        name: 'ECDSA',
        hash: {
            name: 'SHA-256'
        }
    },
    publicKey,
    signature,
    arrayBuffer
);

Expected behavior:
It is acceptable for the first argument to be an object. Should compile.

Actual behavior:
Error TS2345: Argument of type \'{ name: string; hash: { name: string; }; }\' is not assignable to parameter of type \'string | Algorithm\'.\n Object literal may only specify known properties, and \'hash\' does not exist in type \'string | Algorithm\'.

Example 4

crypto.subtle.importKey('spki', spki, {
    name: 'ECDSA',
    namedCurve: 'P-256'
}, true, ['verify']);

Expected behavior:
It is acceptable for the third argument to be an object. Should compile.

Actual behavior:
Error TS2345: Argument of type \'{ name: string; namedCurve: string; }\' is not assignable to parameter of type \'string | Algorithm\'.\n Object literal may only specify known properties, and \'namedCurve\' does not exist in type \'string | Algorithm\'.

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