【问题标题】:TS2322 : '(errors: ValidationError[]) => Error' is not assignable to type '(errors: ValidationError[]) => any', why Error is not assignable to anyTS2322:'(errors: ValidationError[]) => Error' 不可分配给类型'(errors: ValidationError[]) => any',为什么错误不可分配给任何
【发布时间】:2021-04-30 13:56:53
【问题描述】:
lib/admin/server/index.ts:87:5 - error TS2322: Type '(errors: ValidationError[]) => Error' is not assignable to type '(errors: ValidationError[]) => any'.
  Types of parameters 'errors' and 'errors' are incompatible.
    Type 'import("/home/xxxxxx/backend/node_modules/@nestjs/common/interfaces/external/validation-error.interface").ValidationError[]' is not assignable to type 'import("/home/xxxxx/backend/node_modules/class-validator/types/validation/ValidationError").ValidationError[]'.

87     exceptionFactory(errors: ValidationError[]): Error {

我将 nestjs 从 7.0 更新到 7.6,我遇到了这些错误,我对 TS 有点熟悉,但无法理解“错误”的含义,即错误不能分配给“任何” .

如果有人能提供 Nest.js 的 ChangeLog 的链接会很有帮助,因为我找不到它

-谢谢

【问题讨论】:

    标签: node.js typescript nestjs


    【解决方案1】:

    确保您从 nestjs 界面导入 validationError[]

    Error 应该是any 的子集,因为任何只是让 typescript 知道您选择退出类型检查。

    【讨论】:

    • The Error Resolved when imported from Nest's interface而不是Class-validator,但是nest又使用class-validators接口本身,所以为什么会抛出错误
    猜你喜欢
    • 1970-01-01
    • 2019-09-08
    • 2022-07-28
    • 2023-01-31
    • 1970-01-01
    • 2021-11-05
    • 2017-04-10
    • 2019-02-07
    • 1970-01-01
    相关资源
    最近更新 更多