【问题标题】:TypeScript (v3.1.3): Aliasing a generically typed interface?TypeScript (v3.1.3):给通用类型接口起别名?
【发布时间】:2018-10-30 06:29:20
【问题描述】:

这就是我需要打字稿做的事情。将为我节省大量的编码。

interface Base<T,TReturn>
{
   x():TReturn<T>

   y<TResult>():TReturn<TResult>
}

interface A<T> extends Base<T,Array>
{
}

interface B<T> extends Base<T,List>
{
}

这可能吗?我该怎么做?

基本概述,我需要一个接口结构,我可以用给定的参数定义返回类型是什么。如果没有上述可能性,我不得不编写接口签名的唯一副本,如下所示:

interface A<T,Array>
{
   x():Array<T>

   y<TResult>():Array<TResult>
}

interface B<T,List>
{
   x():List<T>

   y<TResult>():List<TResult>
}

【问题讨论】:

    标签: typescript generics interface typing


    【解决方案1】:

    不能在泛型Link 中使用泛型。但没有它,你可以做到这一点。铁:Playground

    【讨论】:

      猜你喜欢
      • 2021-09-16
      • 1970-01-01
      • 2019-09-22
      • 2018-09-22
      • 2020-02-28
      • 1970-01-01
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多