TypeScript confusion

Can anyone explain why third-line errors but the fourth line works?
type First<T> = T extends any[] ? T[0] : never;

const myarr = [1, 2, 3]

type FirstItem = First<myarr>; // This errors saying you should pass type instead of value

type FirstItem1 = First<[1, 2, 3]> // This works even if we are passing value
type First<T> = T extends any[] ? T[0] : never;

const myarr = [1, 2, 3]

type FirstItem = First<myarr>; // This errors saying you should pass type instead of value

type FirstItem1 = First<[1, 2, 3]> // This works even if we are passing value
2 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Samip Poudel
Samip PoudelOP3y ago
ahh makes a lot of sense now. Thanks @matee
Want results from more Discord servers?
Add your server