Field Names that are all caps cause Typescript Error.
While working with my database I noticed that , having a record with all caps caused Typescript error
Removing the OTP field works removed the Typescript error. The error does not appear in Xata playground so I was oblivious to it. Is this a Typescript thing ? Can I safely suppress the warning since it works, at least in the Playground?
Below are images and videos if it helps
14 Replies
I can provide the schema if needed
Hi, was the OTP field newly introduced maybe? Could it be that it is not included in the generated file in use (src/xata.ts)?
In case the client file was generated before the OTP field was added to the schema, the command "xata codegen" or "xata pull main" (where main, the branch in use) needs to be issued on the terminal in order to pull the latest changes from Xata upstream and generate an up to date client file.
Note the Xata Playground uses the current db schema at the moment of page load, so it's up to date (unless the schema is edited on another tab after loading the Playground!), which likely hints why you didn't have this error there
Hi, sorry for taking too long. The OTP field was introduced less than 20 minutes before I started having this issue. I ran
xata pull main
before trying to test it locally.
trying to pull confirms that there are no new migrations to pull
Should o provide my Xata.ts file?The client file would probably tell half the story, we should check what's up with the migration history of this field instead and make sure it's printed out in the client file. If you'd like you can toggle "Allow support to view your workspace" in your workspace settings, let me know of the db:branch so I can investigate this
On your end, you can also try "xata codegen" too. Check if the OTP field exists in the client.ts. Note the default location is src/xata.ts, if you have customized the location of the file where your project uses it from, you'll need to add the
-o /path/to/xata.ts
parameterHi,
I can confirm that OTP field exists in xata.ts. And one migration file. I went ahead to enable Support for Xata. Any other information I can provide?
Xata.ts is truncated
Thank you for granting us access! I've double checked the database and the client file, all seems to be in place. I verified in my local env that the type for the OTP column does not error, see:
Can you show the part of the code where you import the xata client? Do you import from ./src/xata.ts relative to where your current file is, or from some other location?
hi, my apologies for the late replies.
xata.ts
is located at src/lib/xata.ts
The file I am trying to call it from is at src/routes/api/testing/+server.ts
So there might also be a User error from me. Copilot completed the initilization of xata leading me to start create it like this:
And I didn't not second guess it, because I could still use it to get data from the DB.
while I was cross checking your example line by line with mine, i noticed my unusual initialization, I checked everywhere else in my codebase just to see I only made this mistake here.
Hower correcting to const xata = getXataClient()
gives a different error
This is
src/routes/api/testing/+server.ts
(truncated foe easier replication)
this is xata.ts
at src/lib/xata.ts
this could so be user error on my end. Any help is greatly appreciated.This looks good to me. Your initial config
/** My old Initialization */
is correct actually for SvelteKit, that is how we recommend it in our guide: https://xata.io/docs/getting-started/sveltekit#query-and-list-the-posts
At this point I think it is possible something is cached in your IDE and it doesn't "see" updates with new columns to the xata client file. How about you try copying src/lib/xata.ts
to src/lib/xata2.ts
and in +server.ts
you switch to import { XataClient } from '$lib/xata2';
does your IDE "see" the OTP field then?Hi, I tried everything you suggested above in no particular order and it just worked 🤷♂️ The type errors are gone and it works. Thanks for your help.
That's good news! I must've been an IDE glitch, sometimes cached builds do things like that.