【问题标题】:Trying to generate production version of Express with Typescript尝试使用 Typescript 生成 Express 的生产版本
【发布时间】:2020-07-01 13:50:36
【问题描述】:

我在运行时收到以下错误:npm run clear && tsc -P ./tsconfig.app.json && npm run post:buildtsc -p .

节点版本:v12.13.0 npm:v6.14.2 快递:4

有人已经有同样的问题了吗?

> tsc -p .

node_modules/@types/readable-stream/index.d.ts:14:15 - error TS2417: Class static side 'typeof _Readable' incorrectly extends base class static side 'typeof Readable'.
  The types of '(new Stream.Readable.Duplex(...))._destroy' are incompatible between these types.
    Type '(err: Error | null, callback: (error: Error | null) => void) => void' is not assignable to type '(error: Error | null, callback: (error?: Error | undefined) => void) => void'.
      Types of parameters 'callback' and 'callback' are incompatible.
        Types of parameters 'error' and 'error' are incompatible.
          Type 'Error | null' is not assignable to type 'Error | undefined'.
            Type 'null' is not assignable to type 'Error | undefined'.

14 declare class _Readable extends stream.Readable {
                 ~~~~~~~~~

node_modules/@types/readable-stream/index.d.ts:88:9 - error TS2416: Property '_destroy' in type 'Duplex' is not assignable to the same property in base type 'Duplex'.
  Type '(err: Error | null, callback: (error: Error | null) => void) => void' is not assignable to type '(error: Error | null, callback: (error?: Error | undefined) => void) => void'.
    Types of parameters 'callback' and 'callback' are incompatible.
      Types of parameters 'error' and 'error' are incompatible.
        Type 'Error | null' is not assignable to type 'Error | undefined'.
          Type 'null' is not assignable to type 'Error | undefined'.

88         _destroy(err: Error | null, callback: (error: Error | null) => void): void;
           ~~~~~~~~

node_modules/@types/readable-stream/index.d.ts:88:9 - error TS2416: Property '_destroy' in type 'Duplex' is not assignable to the same property in base type 'Writable'.
  Type '(err: Error | null, callback: (error: Error | null) => void) => void' is not assignable to type '(error: Error | null, callback: (error?: Error | undefined) => void) => void'.
    Types of parameters 'callback' and 'callback' are incompatible.
      Types of parameters 'error' and 'error' are incompatible.
        Type 'Error | null' is not assignable to type 'Error | undefined'.
          Type 'null' is not assignable to type 'Error | undefined'.

88         _destroy(err: Error | null, callback: (error: Error | null) => void): void;
           ~~~~~~~~

node_modules/@types/readable-stream/index.d.ts:88:9 - error TS2416: Property '_destroy' in type 'Duplex' is not assignable to the same property in base type '_Readable'.
  Type '(err: Error | null, callback: (error: Error | null) => void) => void' is not assignable to type '(error: Error | null, callback: (error?: Error | undefined) => void) => void'.
    Types of parameters 'callback' and 'callback' are incompatible.
      Types of parameters 'error' and 'error' are incompatible.
        Type 'Error | null' is not assignable to type 'Error | undefined'.
          Type 'null' is not assignable to type 'Error | undefined'.

88         _destroy(err: Error | null, callback: (error: Error | null) => void): void;
           ~~~~~~~~

node_modules/@types/readable-stream/index.d.ts:102:11 - error TS2720: Class '_Readable.PassThrough' incorrectly implements class 'import("stream").PassThrough'. Did you mean to extend 'import("stream").PassThrough' and inherit its members as a subclass?
  Types of property '_destroy' are incompatible.
    Type '(err: Error | null, callback: (error: Error | null) => void) => void' is not assignable to type '(error: Error | null, callback: (error?: Error | undefined) => void) => void'.
      Types of parameters 'callback' and 'callback' are incompatible.
        Types of parameters 'error' and 'error' are incompatible.
          Type 'Error | null' is not assignable to type 'Error | undefined'.
            Type 'null' is not assignable to type 'Error | undefined'.

102     class PassThrough extends Transform implements stream.PassThrough {
              ~~~~~~~~~~~

node_modules/@types/readable-stream/index.d.ts:138:18 - error TS2749: 'StringDecoder' refers to a value, but is being used as a type here.

138         decoder: StringDecoder | null;
                     ~~~~~~~~~~~~~

node_modules/@types/readable-stream/index.d.ts:164:11 - error TS2720: Class '_Readable.Transform' incorrectly implements class 'import("stream").Transform'. Did you mean to extend 'import("stream").Transform' and inherit its members as a subclass?
  Types of property '_destroy' are incompatible.
    Type '(err: Error | null, callback: (error: Error | null) => void) => void' is not assignable to type '(error: Error | null, callback: (error?: Error | undefined) => void) => void'.
      Types of parameters 'callback' and 'callback' are incompatible.
        Types of parameters 'error' and 'error' are incompatible.
          Type 'Error | null' is not assignable to type 'Error | undefined'.
            Type 'null' is not assignable to type 'Error | undefined'.

164     class Transform extends Duplex implements stream.Transform {
              ~~~~~~~~~


Found 7 errors.

【问题讨论】:

  • 你最近有没有把mac更新到Catalina?

标签: node.js typescript express


【解决方案1】:

尝试添加

"@types/node": "^12.12.7"

到 package.json 中的 devDependencies。那么,

npm install 

它对我有用。干杯!!

【讨论】:

    猜你喜欢
    • 2019-07-11
    • 1970-01-01
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    相关资源
    最近更新 更多