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

JSONData<T> should not return a Partial type #1410

Open
maxfi opened this issue Mar 15, 2024 · 0 comments
Open

JSONData<T> should not return a Partial type #1410

maxfi opened this issue Mar 15, 2024 · 0 comments
Labels
bug Something isn't working needs-triage

Comments

@maxfi
Copy link

maxfi commented Mar 15, 2024

Describe the bug

JSONData should not be a Partial of the record’s type

To reproduce

/**
   Schema:
   
   ```json
    {
      "tables": [{
        "name": "Merchandise",
        "columns": [
           ...
          {
            "name": "description",
            "type": "string",
            "notNull": true,
            "defaultValue": ""
          }
          ...
        }]
      }]
    }
    ```
   */

  const record = await xata.db.Merchandise.select(["description"]).getFirst();
  if (!record) throw new Error("No merchandise found");
  console.log(record); // Type: const record: SelectedPick<MerchandiseRecord, "description"[]>
  console.log(record.description); // Type: (property) description: string
  const serialized = record.toSerializable(); // Type: const serialized: JSONData<MerchandiseRecord>
  console.log(serialized.description); // Type: (property) description?: string | undefined

Expected behavior

The type of serialized.description should be the same as record.description. Ie, the type should be Type: (property) description: string not Type: (property) description?: string | undefined.

Software version

  • @xata.io/client: ^0.29.3
  • typescript: 5.4.2
  • $ xata --version : @xata.io/cli/0.15.10 linux-x64 node-v18.17.0

Additional context

Current workaround:

const record = await xata.db.Merchandise.select(["description"]).getFirst();
if (!record) throw new Error("No merchandise found");
const serialized = record.toSerializable() as unknown as (typeof record)

Discord: https://discord.com/channels/996791218879086662/1208988586532282388

@maxfi maxfi added the bug Something isn't working label Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage
Projects
None yet
Development

No branches or pull requests

1 participant