Weird typescript error
Hi all, im getting a typescript error i dont understand why im getting.
As you can see selectedQuestion is assigned the type that you can see, ie a object called SeenQuestions along with some type extensions. The type SeenQuestion absolutley has a property called .questionType - so why am i getting this error?
Help greatly appreciated
![](https://cdn.answeroverflow.com/1126868442633486436/Screenshot_2023-07-07_at_15.31.07.png)
![](https://cdn.answeroverflow.com/1126868442910306404/Screenshot_2023-07-07_at_15.31.35.png)
10 Replies
So to simplfy, im getting an error when trying to access .questionType, even though it exists on the object
Here is the error that im getting
![](https://cdn.answeroverflow.com/1126868747123167325/Screenshot_2023-07-07_at_15.34.02.png)
Looks like you are trying to get the property from an array.
hmm yes you are correct
but im setting the type like this,
(typeof savedQuestions.data)[] | null
shouldn't the square brackets instead look at the elements inside of the array?Try putting [number]
tried that
![](https://cdn.answeroverflow.com/1126881362704605265/Screenshot_2023-07-07_at_16.24.09.png)
got this error in the terminal also
Type error: Type '(SeenQuestions & { relatedXyz: Xyz | null; relatedKva: Kva | null; relatedNog: Nog | null; relatedDtk: Dtk | null; relatedOrd: Ord | null; relatedLas: Las | null; relatedMek: Mek | null; })[] | undefined' has no matching index signature for type 'number'.
Cause it could be undefined?
If you want to get questionType for each element in the array, try using map. If you expect to have a single element then something is wrong and nobody can tell without the full code (try a link on typescript playground)