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

Better support for exactOptionalPropertyTypes #960

Open
atilafassina opened this issue Mar 23, 2023 · 0 comments
Open

Better support for exactOptionalPropertyTypes #960

atilafassina opened this issue Mar 23, 2023 · 0 comments
Labels
bug Something isn't working needs-triage

Comments

@atilafassina
Copy link
Contributor

I found a small issue with our typegen. Happened to me working with one of Astro's TS presets, but can happen with anyone using exactOptionalPropertyTypes: true.

Astro: Astro CLI offers different configs of TypeScript, this project was using the "strictest", among some settings there was exactOptionalPropertyTypes: true.

This config treats undefined differently than unset because they behave differently for "prop" in object check, undefined brings a false positive.

Because of that, formatting a records array was yielding incompatible types between what was coming out of my .map and what DBRecord was typed.

a prop: undefined coming in to a .map leaves as unset. But the type definition prop?: 'value' | null doesn't accept it, instead it would have to be prop?: 'value' | null | undefined
To Reproduce

Reproducing

Set a TS project with exactOptionalPropertyTypes: true.

💡 Exact reproduction could be setting a brand new Astro project with strictest TS preset.

  1. Generate types via the CLI and fetch a list of records with getPaginated, getAll, or getMany.
  2. Take the record list and go through a records.map(), for example split blog posts per publishing month
  3. The return type of this map would then be { [key:string]: PostRecord[] }
  4. TSC will complain there isn't overload between those types and will suggest adding undefined as a target value too.

Expected behavior

Overload matches.

Software version

package version
@xata.io/client ^0.21.6
@xata.io/cli 0.11.18
@atilafassina atilafassina added the bug Something isn't working label Mar 23, 2023
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