Skip to content

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

@XiaopingHu

Description

@XiaopingHu

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的联合类型

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions