Skip to content

Query ResultSet.asMappedResults() isn't useable #307

@bbahrman

Description

@bbahrman

When running a query and getting ResultSet.asMappedResults(), a QueryResultMap is returned. While factually accurate, the QueryResultMap isn't useable since if you assign it to another type/interface there's no overlap.

For example, this
const folderLookup: { id: number }[] = query.runSuiteQL({ query:SELECT id from MediaItemFolder WHERE parent = 1522749 AND name = '${folderName}'}).asMappedResults();
Will throw an error:

TS2322: Type  QueryResultMap[]  is not assignable to type  { id: number; }[] Property  id  is missing in type  QueryResultMap  but required in type  { id: number; }

The solution that I've used for a while has been to convert to any and then to the type I want
const folderLookup: { id: number }[] = query.runSuiteQL({ query:SELECT id from MediaItemFolder WHERE parent = 1522749 AND name = '${folderName}'}).asMappedResults() as any;
But doing so means that you are now using any which fails standard linting and is an extra step to write every time which can lead to errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions