Skip to content
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

#307 Assign type of any to asMap and asMappedResults #308

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions N/query.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ interface CreateColumnOptions {

/**
* An alias for this column. An alias is an alternate name for a column, and the alias is used in mapped results.
* In general, the alias is an optional property.
*
* In general, the alias is an optional property.
*
* To use mapped results, you must specify an alias in the following situations:
* 1. You must specify an alias for a column when the column uses a formula.
* 2. You must specify an alias when two columns in a joined query use the same field ID.
Expand Down Expand Up @@ -149,8 +149,8 @@ interface CreateColumnWithFormulaOptions {

/**
* An alias for this column. An alias is an alternate name for a column, and the alias is used in mapped results.
* In general, the alias is an optional property.
*
* In general, the alias is an optional property.
*
* To use mapped results, you must specify an alias in the following situations:
* 1. You must specify an alias for a column when the column uses a formula.
* 2. You must specify an alias when two columns in a joined query use the same field ID.
Expand Down Expand Up @@ -207,7 +207,7 @@ export interface RunSuiteQLOptions {
query: string;

params?: Array<string | number | boolean>;

customScriptId?: string;
}

Expand Down Expand Up @@ -602,7 +602,10 @@ export interface Condition {
readonly component: Component;
}

export type QueryResultMap = { [fieldId: string]: string | boolean | number | null }
export type LowercaseKeys<T> = {
[K in keyof T as Lowercase<K & string>]: T[K];
};

/**
* Set of results returned by the query.
*/
Expand Down Expand Up @@ -637,8 +640,7 @@ export interface ResultSet {
* A mapped result is a JavaScript object with key-value pairs.
* In this object, the key is either the field ID or the alias that was used for the corresponding query.Column object.
*/
asMappedResults(): Array<QueryResultMap>;
asMappedResults<QueryResultMap>(): Array<QueryResultMap>;
asMappedResults<T extends LowercaseKeys<T>>(): LowercaseKeys<T>[];
}

/** Corresponds to a single row of the ResultSet. */
Expand All @@ -661,8 +663,7 @@ export interface Result {
* A mapped result is a JavaScript object with key-value pairs.
* In this object, the key is either the field ID or the alias that was used for the corresponding query.Column object.
*/
asMap(): QueryResultMap;
asMap<QueryResultMap>(): QueryResultMap
asMap<T extends LowercaseKeys<T>>(): LowercaseKeys<T>;
}

/**
Expand Down Expand Up @@ -752,7 +753,7 @@ interface Period {
readonly code: string;
/**
* The type of the period. This property uses values from the query.PeriodType enum.
* If you create a period using query.createPeriod(options) and do not specify a value for the options.type
* If you create a period using query.createPeriod(options) and do not specify a value for the options.type
* parameter, the default value of this property is query.PeriodType.START.
*/
readonly type: string;
Expand Down Expand Up @@ -1259,7 +1260,7 @@ export enum FieldContext {
CONVERTED = "CONVERTED",
/** Displays consolidated currency amounts in the base currency. */
CURRENCY_CONSOLIDATED = "CURRENCY_CONSOLIDATED",
/**
/**
* Displays user-friendly field values.
* For example, for the entity field on Transaction records, using the DISPLAY enum value displays the name of the entity instead of its ID.
*/
Expand Down