How to get Type of Array in Typescript generics

后端 未结 5 1936
半阙折子戏
半阙折子戏 2020-12-18 06:56

I have a method like this:

public select(fieldName: keyof TType)

Where TType could be an array type. In case of an array type

5条回答
  •  轮回少年
    2020-12-18 07:08

    Using TType[0] as the type is working for me in practice. So, in your example:

    public select(fieldName: keyof TType[0])
    

    As ugly as that is, it seems to work!

提交回复
热议问题