www.executeprogram.com/courses/advanced-typescript/lessons/any-and-unknown-in-generic-constraints
1 Users
0 Comments
13 Highlights
0 Notes
Tags
Top Highlights
we want a generic object type that contains an items array
ensure that items is actually an array
first attempt is <A extends Array>
rray requires a generic type argument, but we didn't give one.
Array
We need to provide a type argument to Array
any
Normally, any
Surprisingly, our ItemsObject type is actually safe even with the <A extends Array<any>>
the any and unknown types both work and are equally safe.
ther developer reading your code might not know that any is safe in this one specific case
Although extends Array<any> and extends Array<unknown> are both safe here, we recommend using unknown in practice.
wraps a set in an object
Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.