-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
🐛 Bug Report: Document autocompletion for Databases.createDocument broken #76
Comments
I'm not sure why the Personally, I want the type safety of Typescript, so I would prefer if the /* models.ts */
export type Document = {
$id: string;
$collectionId: string;
$databaseId: string;
$createdAt: string;
$updatedAt: string;
$permissions: string[];
};
export interface AnyDocument extends Document {
[key: string]: any;
}
/* databases.ts */
async createDocument<Document extends Models.Document = Models.AnyDocument>(
databaseId: string,
collectionId: string,
documentId: string,
data: Omit<Document, keyof Models.Document>,
permissions?: string[],
): Promise<Document> {
/* ... */
} That would probably solve this issue as well. |
Correct, this is to prevent errors when someone just calls
This is a great idea! We generate our SDKs using our sdk-generator and the template for the |
Opening this for contributors to see if they can update the SDK generator to add this behavior. |
in our sdk generator we can shift the logic of adding index signature to creating the {% if definition.additionalProperties %}
/**
* {{ definition.description | trim }} with additional properties
*/
export interface Any{{ definition.name | caseUcfirst }}{{ definition.name | getGenerics(spec, true) | raw }} extends {{ definition.name | caseUcfirst }}{{ definition.name | getGenerics(spec, false) | raw }} {
[key: string]: {% if definition.additionalProperties.type %}{{ definition.additionalProperties | getType(spec) }}{% else %}any{% endif %};
}
{% endif %} then we can add We also need to take care of cases where the entire interface is just using the index signature like: /**
* Preferences
*/
type Preferences = {
[key: string]: any;
}; then we don't want the any decalaration. @loks0n can you confirm the naming for this? currently we just have index signature for |
Opening this for contributions. Feel free to check out the repo and raise a pr! https://github.com/appwrite/sdk-generator/ |
👟 Reproduction steps
When using an IDE/editor supporting autocompletion with the Typescript Language Server, such as VS Code.
Calling
Databases.createDocument
with a type parameter:👍 Expected behavior
I should see the properties I defined in the
ProjectModel
interface when VS Code autocompletes the code inside the curly brackets.👎 Actual Behavior
VS Code shows identifiers from the function scope, but not the properties defined in the
ProjectModel
interface:Possible solution
I think this is caused by the
data
argument ofDatabases.createDocument
having the typeOmit<Document, keyof Models.Document>
.Since
Models.Document
contains a string index signature, the value ofkeyof Models.Document
is probablystring | number
. That would remove all properties from theDocument
type parameter, basically turning it into an empty object type ({}
).🎲 Appwrite version
Different version (specify in environment)
💻 Operating system
MacOS
🧱 Your Environment
Appwrite Cloud
Appwrite web SDK version:
VS Code version information:
MacOS version:
👀 Have you spent some time to check if this issue has been raised before?
🏢 Have you read the Code of Conduct?
The text was updated successfully, but these errors were encountered: