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

同名interface生成解析错误 #11

Closed
Micjoyce opened this issue Sep 14, 2018 · 2 comments
Closed

同名interface生成解析错误 #11

Micjoyce opened this issue Sep 14, 2018 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Micjoyce
Copy link

Micjoyce commented Sep 14, 2018

假设在service目录下有一个文件为
service/application.ts

import { Context, Service } from 'egg'

export default class ApplicationService extends Service {
  getData () {
    return 'hello world'
  }
}

自动生成的typing文件如下:
typing/app/service/index.d.ts

import 'egg'; // Make sure ts to import egg declaration at first
import Application from '../../../app/service/application';

declare module 'egg' {
  interface IService {
    application: Application;   // 这里的Application会被只想到egg下的Application,不能正确解析
  }
}

如果此时在controller中访问 ctx.service.application.getData()getData这个方法并没有真正的被解析道ctx.service.application对象上。

个人的建议能否在生成的时候添加prefix配置,使得生成的typing文件如下

typing/app/service/index.d.ts

import 'egg'; // Make sure ts to import egg declaration at first
import PrefixApplication from '../../../app/service/application';

declare module 'egg' {
  interface IService {
    application: PrefixApplication;   // 生成的prefix
  }
}

这样处理完之后就可以正确解析了。

@whxaxes
Copy link
Member

whxaxes commented Sep 14, 2018

嗯,这算是个 bug 了,我修复一下

@whxaxes whxaxes added the bug Something isn't working label Sep 14, 2018
@whxaxes whxaxes self-assigned this Sep 14, 2018
@whxaxes
Copy link
Member

whxaxes commented Nov 29, 2018

fixed in 1.16.0

@whxaxes whxaxes closed this as completed Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants