繁体   English   中英

TypeScript为“ as X”定义接口

[英]TypeScript define interface for “as X”

我有以下代码:

const [surveyResponses, totalCount]: [SurveyResponse[], number] =
await this.someRepo.findByFilters(filter) as [SurveyResponse[], number];

是否可以给as [SurveyResponse[], number]部分提供接口? findByFilters函数是否返回分页结果,所以我想为每个接口都有一个接口。

不是接口,而是类型别名,是的:

type X = [SurveyResponse[], number];

const [surveyResponses, totalCount]: X = ...
await this.someRepo.findByFilters(filter) as X;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM