错误 - return 类型不一致(使用闭包编译器 Promise)
Error - inconsistent return type (with closure compiler Promise)
我正在尝试编写一个进行 API 调用和 returns Promise 的函数。这是我的函数定义:
/**
* Gets the IAM policy for a service account. Wraps getIamPolicy endpoint:
* https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/getIamPolicy
* @param {!Project} project
* @param {string} email - Unique email for a service account.
* @return {!angular.$q.Promise<!Object<!string, !Policy>>}
*/
getIamPolicy(project, email) {
const path = constructPath_(project, email) + ':getIamPolicy';
return this.apiClient_.request({method: 'POST', path}, this.config_)
.then(response => { debugger; });
}
我正在使用闭包编译器,这会引发编译错误:
service-account-service.js:124: ERROR - inconsistent return type
found : angular.$q.Promise<undefined>
required: angular.$q.Promise<Object<string,Policy>>
return this.apiClient_.request({method: 'POST', path}, this.config_)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
我做错了什么?我应该如何回报承诺?
我之前使用 apiClient_.request 辅助函数编写的函数运行良好。我应该从中返回相同的值。apiClient_.request.
政策和项目在外部文件中定义(我相信是正确的)。我也在使用 Angular 1.4
错误表明您 return 的 Promise<undefined>
是正确的。当 this.apiClient_.request
辅助函数 returning 一个 Promise 时,Promise 的 return 类型(<undefined>
位)被 .then(response => { debugger; })
代码覆盖。即,该代码没有 return 语句,所以它是 returning undefined
!
因此,当我将代码更改为:
时它起作用了
return this.apiClient_.request({method: 'POST', path}, this.config_)
.then(response => {
debugger;
return response;
});
我正在尝试编写一个进行 API 调用和 returns Promise 的函数。这是我的函数定义:
/**
* Gets the IAM policy for a service account. Wraps getIamPolicy endpoint:
* https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/getIamPolicy
* @param {!Project} project
* @param {string} email - Unique email for a service account.
* @return {!angular.$q.Promise<!Object<!string, !Policy>>}
*/
getIamPolicy(project, email) {
const path = constructPath_(project, email) + ':getIamPolicy';
return this.apiClient_.request({method: 'POST', path}, this.config_)
.then(response => { debugger; });
}
我正在使用闭包编译器,这会引发编译错误:
service-account-service.js:124: ERROR - inconsistent return type
found : angular.$q.Promise<undefined>
required: angular.$q.Promise<Object<string,Policy>>
return this.apiClient_.request({method: 'POST', path}, this.config_)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
我做错了什么?我应该如何回报承诺?
我之前使用 apiClient_.request 辅助函数编写的函数运行良好。我应该从中返回相同的值。apiClient_.request.
政策和项目在外部文件中定义(我相信是正确的)。我也在使用 Angular 1.4
错误表明您 return 的 Promise<undefined>
是正确的。当 this.apiClient_.request
辅助函数 returning 一个 Promise 时,Promise 的 return 类型(<undefined>
位)被 .then(response => { debugger; })
代码覆盖。即,该代码没有 return 语句,所以它是 returning undefined
!
因此,当我将代码更改为:
时它起作用了return this.apiClient_.request({method: 'POST', path}, this.config_)
.then(response => {
debugger;
return response;
});