-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query ResultSet.asMappedResults() isn't useable #307
Comments
I've created #308 as a proposed fix |
I've had some success defining a type and casting the type using type someCoolType = query.QueryResultMap & { ... }
// then
const queryResults.asMappedResults() as someCoolType[]; |
Really, what it should be is something like this ... type LowercaseKeys<T> = {
[K in keyof T as Lowercase<K & string>]: T[K];
};
asMappedResults<T extends LowercaseKeys<T>>(): LowercaseKeys<T>[]; This will save developers from wondering why all the camelcase properties they expect to be returned from SuiteQL are suddenly converted to lowercase |
☝️ That's a good point. I would then point out the convention with SQL is it use |
Thanks @darrenhillconsulting for the idea and example. I added it in and have updated my pull request. @lyatziv - agreed, I like the validation of the interface for things that will break and then assume most people are using snake_case as the solution to that. |
…bahrman/typings-suitescript-2.0 into headintheclouddev#307-query-result-map
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:
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.
The text was updated successfully, but these errors were encountered: