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

response的联合类型any会导致this指向约束失效,导致ts报错 #137

Open
XiaopingHu opened this issue May 24, 2024 · 0 comments

Comments

@XiaopingHu
Copy link

declare interface MockMethod {
url: string;
method?: MethodType;
timeout?: number;
statusCode?: number;
response?: ((this: RespThisType, opt: {
url: Recordable;
body: Recordable;
query: Recordable;
headers: Recordable;
}) => any);
rawResponse?: (this: RespThisType, req: IncomingMessage, res: ServerResponse) => void;
}
response的联合类型any会导致this指向约束失效,当response是个函数时,在这个函数中调用this.res时,会报res不存在于MockMethod类型中
建议取消any的联合类型

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

No branches or pull requests

1 participant