Skip to content

SubtleCrypto methods return PromiseLike instead of Promise #37756

@taymonbeal

Description

@taymonbeal

TypeScript Version: 3.9.0-dev.20200328

Search Terms:
WebCrypto, web crypto, SubtleCrypto, subtle, PromiseLike

Expected behavior:
Should compile with no errors.

Actual behavior:

Type 'PromiseLike<CryptoKey>' is missing the following properties from type 'Promise<CryptoKey>': catch, [Symbol.toStringTag]

Related Issues:
microsoft/TypeScript-DOM-lib-generator#843 (pull request that should fix this)
microsoft/TypeScript-DOM-lib-generator#60
microsoft/TypeScript-DOM-lib-generator#47

Code

const keyPromise: Promise<CryptoKey> = crypto.subtle.generateKey({name: 'AES-GCM', length: 256}, true, ['encrypt']);
Output
"use strict";
const keyPromise = crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt']);
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}

Playground Link: Provided

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions