Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复类型推论的错误,引入 @types 描述文件 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jsjzh
Copy link

@jsjzh jsjzh commented Dec 3, 2020

bug fix

问题描述

在使用时发现 typescript 的类型推论无法正常运作,如下图

image

可见泛型 M 按规范传入之后,并未在 Promise<M> 中正确返回,并且在实际情况中,我看到返回都是 any

问题调查

  1. 经调查发现,sequelize 在 sequelize/types/lib/promise.d.ts 使用了 @types/bluebird,这个描述文件覆写了 Promise 的描述
  2. sequelize/types/lib/model.d.ts 中大量引入了 sequelize/types/lib/promise.d.tsPromise
  3. 在没有安装 @types/bluebird 时,sequelize/types/lib/promise.d.ts 使用的 Promise 就会找不到,变成了 any,也就重现了上图的情况

解决途径

  1. 正确安装 @types/bluebird 依赖,并将其设置为 dependencies,保证用户在使用此依赖时同时也安装 @types/bluebird 描述文件
  2. 在查看了 sequelize 的 gitpage 之后,发现该项目也在「installation」中提示安装 @types/bluebird,链接如下 sequelize-typescript#installation

ps: 当然,通过用户自己安装 @types/bluebird 也可以解决问题,但是 egg-typescript-sequelize 插件作为对 sequelizesequelize-typescript 的一层封装,这个描述文件依赖由插件来安装更好

ps2: sequelize 的使用者也有同样的疑惑。。。这里给上 issues 地址 sequelize/issues/10928

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant