-
Notifications
You must be signed in to change notification settings - Fork 101
Description
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.