I am likely missing something in the "TYPING" of my objects but despite my interface slot is coming up as an any type.
Property 'slot' does not exist on type '{ slot?: number[] | undefined; tile?: number[] | undefined; cardOne?: number | null | undefined; cardTwo?: number | null | undefined; }[]'.Vetur(2339)
interface TableMatchInterface {
slot?: (number) [];
tile?: (number) [];
cardOne?: (number)|null;
cardTwo?: (number)|null;
}
What am I doing wrong?
CodePudding user response:
Because you are adding the "?" symbol after the slot property, typescript inferred that the object property could have 2 values, either number[] or undefined. If you are really sure that you already have a real value and not an undefined one, you can use "!" to tell typescript to relax.
siteStore.tableMatch.slot[0]!
You can have a look about the "!" symbol here:
CodePudding user response:
The error indicates that tableMatch
is an array of TableMatchInterface
objects. Did you mean something like
siteStore.tableMatch[0].slot
Either that or check that the typing on tableMatch
is actually TableMatchInterface
, and not something like TableMatchInterface[]