-
Notifications
You must be signed in to change notification settings - Fork 63
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
TypeScript Type Definitions #49
base: main
Are you sure you want to change the base?
Conversation
Thanks @MarkHerhold! Will review this soon. |
Unfortunantly, the options object is completely wrong still. I'll have to take another look at it. |
@jeremydaly Ok I figured out what you were doing with options and made some changes! BTW, something I noticed - it's probably not a good idea to mutate global objects in this lib because you don't document the side effects and users don't expect it. IMO, it's best to leave that up to the user. |
Having typings support will be a nice improvement. It would be interesting to have a generic parameter for const result = await db.query<RecordType>('SELECT * from records');
const record = result.records[0]; Something like: export interface iDataAPIClient {
query<T>(sql: string, params?: [] | unknown): Promise<iDataAPIQueryResult<T>>;
query<T>(obj: { sql: string; parameters: [] | unknown; database: string; hydrateColumnNames?: boolean }): Promise<iDataAPIQueryResult<T>>;
}
export interface iDataAPIQueryResult<T> {
records: Array<T>;
} |
@rraziel good idea, will give it a shot 👍 |
} | ||
|
||
interface iQuery<T> { | ||
(sql: string, params?: [] | unknown): Promise<T>; // params can be [] or {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the generics, you can do something like this (instead of making iQuery
itself a generic):
(sql: string, params?: [] | unknown): Promise<T>; // params can be [] or {} | |
<T = any>(sql: string, params?: [] | unknown): Promise<T>; // params can be [] or {} |
Usage:
client.query<{ name: string; age: number }[]>('SELECT * from table';)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realised this is the same as @rraziel 's suggestion 😅
Anything I can do to help out on this one, @jeremydaly? The type definitions on DefinitelyTyped have what I think might be an errant type reference:
This is causing errors in our Reactive Native app because RN uses browser timers and referencing the node types redefines the timer functions, causing TSC errors b/c we're using |
Hi, any chances that will be merged soon? |
First pass at TS types from #2