How do I extract a type from an array in typescript?

This is possible with Typescript 2.8+. You can declare an Unpacked<T> type as follows:

type Unpacked<T> = T extends (infer U)[] ? U : T;

Now you can do

type InnerCacheType = Unpacked<CacheType>; // Event | User

This is a condensed definition of the Unpacked type given in the documentation.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)