My headless CMS is responsible for generating all types in my GraphQL schema.
Upon querying, I receive a result that contains an array which I can manipulate.
However, when attempting to use filter, map, or find methods on the returned array, an error message stating 'Property 'filter/map/find' does not exist on type 'TypeName'' is received.
To resolve this, a quick fix through Visual Studio can be applied, but it generates the types in an automatically generated file. Alternatively, I extended the types in a separate file and found success.
import { DataEntity } from './__generated__/graphql'
interface DataEntityWithMethods extends DataEntity {
filter(arg0?: (grouping: DataEntity) => DataEntity): unknown
find(arg0?: (group: DataEntity) => boolean): unknown
map(arg0?: (group: DataEntity) => void): unknown
}
export type { DataEntityWithMethods }
Though effective, I question if this is the best approach. It seems odd that I need to manually add default JavaScript methods to the created types.
Does TypeScript typically function in this manner?