-
Notifications
You must be signed in to change notification settings - Fork 7
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
Simplify Typings #304
Comments
Hi @panoply Thanks for submitting the issue! I think this can be distilled down to: Using interfaces for query responses is not well supported. I can confirm the issue. You can add As for background, we want to make it clear that the driver only decodes results into a narrow set of results, particularly that it doesn't automatically decode into custom classes. For example, if you had a custom |
FWIW: You can type check against classes. |
Fauna does not decode responses into user classes, so user classes cannot be a valid The reason we use Lines 363 to 384 in 6baf2b1
I am still working through why Changing |
Okay, fascinating... interface User {
name: string;
email: string;
}
const query = fql`{
name: "Alice",
email: "alice@site.example",
}`;
const response = await client.query<User>(query); But if I update the interface with property values besides interface User {
name: number;
email: string;
} But only the FIRST property. The following also compiles interface User {
name: string;
email: number;
}
Actually, the |
The current type system setup is unnecessarily complex and problematic. Given the expectation of an index signature and rather extraneous naming conventions, using TypeScript (TS) often results in a mild headache, requiring developers to meticulously code just to meet the driver's expectations. In most projects,
interface
is the preferred for type definition, with type aliases generally reserved for union or intersection types.The driver's assumption of type alias expressions leads to cumbersome workarounds. Consider the following example:
This interface is straightforward and should ideally integrate seamlessly with the driver's response model. However, the reality is less ideal:
This setup results in errors because the
QueryValue
constraint isn't met by ourFoo
interface. Even when we adjust as follows:The compiler still complains due to the constraints on
QueryValue
. The solution often involves extending the interface:This works but introduces new issues:
Assumption of Use: It assumes
Foo
is exclusively for query usage, which might not always be the case.Type Narrowing: Extending
Document
necessitates creating yet another type for accurate narrowing:This becomes problematic because:
QuerySuccess
type exposes adata
property, making index access types less viable without creating an additional interface.Foo
interface elsewhere might lead to type conflicts due to the additional properties fromDocument
.I don't really understand why such exhaustive measures need to take place. What should be a simple generic type parameter has turned into:
Document
.This process overly complicated and it's not necessary, furthermore what is the reasoning here? The generic can simply be augmented and resolve, there is no need for all this.
The text was updated successfully, but these errors were encountered: