TypeScript SubtleCrypto方法返回PromiseLike而不是Promise

1tu0hz3e  于 2022-10-29  发布在  TypeScript
关注(0)|答案(1)|浏览(141)

**类型脚本版本:**3.9.0-dev.20200328
搜索词:

WebCrypto,网页加密,SubtleCrypto,微妙的,PromiseLike

预期行为:

编译时应无错误。

实际行为:

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

相关问题:

microsoft/TypeScript-DOM-lib-generator#843(应修复此问题的提取请求)
microsoft/TypeScript-DOM-lib-generator#60
microsoft/TypeScript-DOM-lib-generator#47

代码

const keyPromise: Promise<CryptoKey> = crypto.subtle.generateKey({name: 'AES-GCM', length: 256}, true, ['encrypt']);

输出

"use strict";
const keyPromise = crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt']);

编译器选项

{
  "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链接:**已提供

ttcibm8c

ttcibm8c1#

我已经在microsoft/TypeScript-DOM-lib-generator#843发送了一个PR来修复这个问题。它只需要被审查。

相关问题