TS - how to extract type from Picked array

I have the following type:
type ChallengeInput = {
title: string,
sections: Array<{
title: string;
description: string;
videoId: string;
collectionId: string;
libraryId: number;
}>;
};
type ChallengeInput = {
title: string,
sections: Array<{
title: string;
description: string;
videoId: string;
collectionId: string;
libraryId: number;
}>;
};
And I want to get the type of a Section.
type Section = Pick<ChallengeInput, "sections">[number]
type Section = Pick<ChallengeInput, "sections">[number]
However this throws an error has no matching index signature for type number... Any suggestions?
3 Replies
Sybatron
Sybatron•15mo ago
type Section = ChallengeInput["sections"][number]; this should do the job
Unknown User
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
JulieCezar
JulieCezar•15mo ago
Makes sense, ty both 😄