-
Notifications
You must be signed in to change notification settings - Fork 127
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
Difficulties using explicit typing. #289
Comments
I'm confused and not sure that I understand what you are trying to do, but I don't think your issue in SDK related. Please understand that the issues tracker is not a general dev support forum. In any case better TS support is planned in the future but for now other tasks are with higher priority. If you still think that there is an issue with the JS SDK, then please elaborate more clearly what is the problem that you have and what you are trying to do. |
As a side-note, keep in mind that in step 4 you are importing the type of the default export, which would explain why the error is |
I would say my goal is to have all PocketBase server side interactions fully-typed, I'm trying to follow the generic types and other conventions presented in the README.md here. I've read through other SDK issues in here, as well as a closed PR. It seems that type support is a big task on itself. If such a goal is not currently possible, I understand. Doing the curly braces import errors out on I found a kind of dirty workaround casting types to |
The curly brackets is the correct notation when not targeting the default import but the issue is that the I've submitted a fix in v0.21.2 release. I've tested it locally and it is working correctly for me. If you are still not able to resolve your issue, then please create a minimal reproducible repo and I'll try to investigate it further. |
Latest patch fixes it. VSCodium now reports |
I don't know if this is a TypeScript only-issue (it seems to be).
The type system does weird mental gymnastics when trying to get some props typed on Sveltekit + TypeScript.
Take this as an example:
There, TS types (at least in codium), indicate that
pb_health
type isHealthCheckResponse | null
. Makes total sense so far.+page.svelte
get the PocketBase health variable:Here,
PBHealth
is still detected asHealthCheckResponse | null
.PBHealth
prop. When you try to use it, Sveltekit will whine about it being an implicit any type. Fortunately we know the types we need:+page.svelte
to see this error in the component prop:I'm failing to see where did I declare a
Client
type variable (other thanlocals.pb
). Or how to tell TypeScript that I don't care about that and "forcefully" type such variables.Variations
You can encounter this error earlier if you modify the example function in step 1:
Also returns the same error.
Solutions
One solution I found was to declare the
PBHealth
component prop asany
which totally defies TypeScript's purpose and turns it into blue JS.Another approach is to create an "copy"
Object
from the original variable and try to cast it using Zod or a similar library. But that's plain memory wasting.I'm aware of #152 progress and don't really know if this is related or not.
The text was updated successfully, but these errors were encountered: