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

TS thinks the return type of GoogleSpreadsheetRow<Row>.get("Column") is any rather than Row["Column"] #641

Open
ryanscottaudio opened this issue Jul 26, 2023 · 3 comments

Comments

@ryanscottaudio
Copy link

ryanscottaudio commented Jul 26, 2023

That's pretty much it; it's probably because the type signature of GoogleSpreadsheetRow.get is (key: keyof T) => any rather than <K extends keyof T>(key: K) => T[K] or similar.

I could open a PR to update that if it's okay!

@theoephraim
Copy link
Owner

Oh wow, I totally missed that... Was definitely my intention to return the typed column.

Thanks for the heads up - will push an update shortly!

@theoephraim
Copy link
Owner

Hmm so taking a deeper look and poking around a bit, it looks like for the types on GoogleSpreadsheetRow to really be useful, I'll need to make some more adjustments, since everything is just a string or undefined right now.

First, support the valueRenderOption option when fetching rows - this would allow fetching the bare value. Right now we fetch formatted values, which are always strings. This would mean we could fetch numbers, booleans, etc - but it would still be limited, as none of your formatting which could potentially be useful would apply.

Alternatively (or in addition to rather) perhaps a slightly more complex schema system would help.

This could either be something like providing a transformation function (ie convert the formatted/string version and spit out the values that match your expected types using things like parseFloat, date conversion, etc...), and then an opposite conversion from your types to something google will be happy to write correctly back into the sheet.

Or something like providing a schema object, which defines the types and optionally provide transformation functions for each key - although many of the transformations may be able to be inferred since common types will cover most cases - things like boolean, dates, floats/ints, etc.

This will all make things slightly more complicated than just providing the type only when calling getRows(), however I don't see much of a way around it since we need the type info at runtime to do transformations of the values google is sending back to us.

Open to suggestions too - since I don't actually use this tool on any complex projects...

@jayenashar
Copy link

i think adding valueRenderOption as an option to getRows() would be a quick win

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants