0
我有一段代碼,看起來像這樣如何標記標記函數的返回類型爲自定義類型
import * as Promise from 'bluebird';
import {Response} from '../commonInterfaces/httpService';
getCall(url: string, accessToken: string, extraHeaders: object): Promise<Response> {
let headers = this.getHeaders(accessToken, extraHeaders);
return new Promise((resolve, reject) => {
request({
url: url,
method: "GET",
withCredentials: false,
json: true,
headers: headers
}, (err: Error, response: Response) => {
if (err) {
reject(err)
} else {
resolve(response)
}
});
});
}
和響應的承諾是一個接口
interface Response {statusCode: number, body: object}
和我收到以下錯誤
[ts]
Type 'Bluebird<{}>' is not assignable to type 'Bluebird<Response>'.
Type '{}' is not assignable to type 'Response'.
Property 'statusCode' is missing in type '{}'.
可能是什麼問題?