Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
7 replies
Vimes

Typescript with array data from shitty CMS

I'm trying to learn this typescript thing Theo's banging on about all the time but can't figure out how to do TS with arrays.

I get an array from my CMS that fits with the ContentProps I made
type ContentProps = {
    level: string; 
    name: string; 
    beskrivelse: string; 
    vurdering?: string; 
}


This is the exact return I get from the CMS, but trying to typecheck this I get an error stating "allContent does not exist on type ContentProps[]"

This is my attempt so far
type ContentProps = {
    level: string; 
    name: string; 
    beskrivelse: string; 
    vurdering?: string; 
}

const AuditConditionalRenderer = ({ allContent }: Array<ContentProps>) => { 


PS: This works in the front end, but TS is not happy. Any ideas on what I'm doing wrong 🤔
image.png
Was this page helpful?