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•2y ago
type Section = ChallengeInput["sections"][number]; this should do the job
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
JulieCezar
JulieCezarOP•2y ago
Makes sense, ty both 😄
Want results from more Discord servers?
Add your server