-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
ts 模式下,egg-mongoose 创建的 model 不能在 ctx.model 下成功获取到代码提示 #2796
Comments
Translation of this issue: ts mode, model created by egg-mongoose can not successfully get code hints under ctx.model[Example] (https://github.com/gu-xionghong/egg-example) According to the project created by the official document |
但是支持程度只是说你写出 关于联想出 |
@BaffinLee 谢谢解答 |
@gu-xionghong 借助 egg-ts-helper 自动生成的 typings/app/model 目录下 *.d.ts, 其中包含一个 egg scope 下的 import * as mongoose from 'mongoose';
declare module 'egg' {
// extend app
interface Application {
model: IModel;
}
// extend context
interface Context {
model: IModel;
}
} 这样就会有 |
@atian25 @gu-xionghong 确实 // tshelper.js
module.exports = {
watchDirs: {
model: {
path: 'app/model',
generator: 'function',
interface: 'IModel',
declareTo: 'Context.model',
// interfaceHandle: val => `ReturnType<typeof ${val}>`, 这一行不需要
}
}
} |
module.exports = {
watchDirs: {
model: {
path: 'app/model',
generator: 'function',
interface: 'IModel',
declareTo: 'Context.model',
}
}
} function 这个 generator 就是 |
@whxaxes 你说的这种我之前试了 不加 interfaceHandle: val => `ReturnType<typeof ${val}>`, 的话,只有 |
@vagusX function 的 generator 就是给 interfaceHandle 一个默认值,就是 |
@whxaxes 你说的是对的 我又试了一下 确实是不需要写 |
示例
按照官方文档
npx egg-init --type=ts showcase
创建的项目,引入egg-mongoose
的文档示例,在Controller
下使用ctx.model
不能够获取到对应的User model
的提示,typeings/app/model/index.d.ts
有成功创建,参考如图:The text was updated successfully, but these errors were encountered: