0 of 6 problems solved0%
2 of 6

Pick Using const Keys

typeof can turn a value into a type. With as const, a tuple keeps literal elements, so typeof FIELDS[number] becomes a union of those literals. Combine this with indexed access to express a precise Pick<...>.

const KEYS = ["id", "title"] as const;
// typeof KEYS[number] is 'id' | 'title'

Use this to build a small preview object from a bigger record.

Your Task

Build a preview object using keys from a const tuple.

  • Declare const ARTICLE_FIELDS = ['id', 'title'] as const.
  • Define type Article = { id: string; title: string; body: string; views: number }.
  • Implement function pickArticlePreview(a: Article): Pick<Article, typeof ARTICLE_FIELDS[number]>.
  • Return a new object with only id and title.