简体   繁体   中英

Typescript generic utility type

Is there any utility type in TS to help me get generic type?

I'm looking for something like GenericType

const foo = ['foo']
type MyStringType = GenericType<typeof foo> // equal to type MyStringType = string


let bar : Promise<number>
type MyNumberType = GenericType<typeof bar> // equal to type MyNumberType = number

I am using jest-axe and in let results: axe.AxeResults; I have TS2503: Cannot find namespace 'axe'. error, Also I cannot import AxeResults I want to use GenericType<ReturnType<typeof axe>>

在此处输入图像描述

在此处输入图像描述

Generic types are usually represented by letters in typescript as in Array<T,U>. Also the most generic type in typescript is any .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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