I have a Value type like this:
export type Value = {
__typename?: 'Value',
key?: Maybe<Scalars['String']>,
label?: Maybe<Scalars['String']>,
value?: Maybe<Scalars['String']>,
};
And a query result type (generated apollo hooks) like this:
Maybe<Maybe<{
__typename?: "Value" | undefined;
} & Pick<Value, "key" | "label" | "value">>[]>
I'm trying to pass this query result to a function:
const getValues = (contacts: Value[]) => {
const values = contacts.map(e => e["value"]);
return values;
};
For some reason, TypeScript says that those types are incompatible. My function call:
getValues( dataFilters!.caseListFilters!.contacts )
TypeScript error:
Argument of type 'Maybe<Maybe<{ __typename?: "Value" | undefined; } & Pick<Value, "key" | "label" | "value">>[]>' is not assignable to parameter of type 'Value[]'.
Type 'null' is not assignable to type 'Value[]'.ts(2345)
Can someone help me to understand what is wrong with these types?
I know that as Value[]
solves the problem but I have no idea why.
getValues( dataFilters!.caseListFilters!.contacts as Value[] //no error )