Skip to content

fix: ts support for all optional keys in data model#5283

Merged
KevinVandy merged 5 commits intoTanStack:mainfrom
jrozbicki:fix-ts-support-for-all-optional-keys-in-data-model
Feb 28, 2024
Merged

fix: ts support for all optional keys in data model#5283
KevinVandy merged 5 commits intoTanStack:mainfrom
jrozbicki:fix-ts-support-for-all-optional-keys-in-data-model

Conversation

@jrozbicki
Copy link
Contributor

Closes #5272

Is object extends T different than T extends object?

Before: Following basic example, if Person had only optional fields DeepKeys would use object extends T and infer string

type Person = {
  firstName?: string
  lastName?: string
  age?: number
  visits?: number
  status?: string
  progress?: number
  address?: {
    city?: string
  }
}

type Test = DeepKeys<Person>
   // ^? type Test = string

After: When that got removed, the same case will fall under T extends object and will nicely infer key names.

type Person = {
  firstName?: string
  lastName?: string
  age?: number
  visits?: number
  status?: string
  progress?: number
  address?: {
    city?: string
  }
}

type Test = DeepKeys<Person>
   // ^? type Test = "firstName" | "lastName" | "age" | "visits" | "status" | "progress" | "address" | "address.city"

Did I missed something obvious? It was probably there for a reason

Copy link
Member

@KevinVandy KevinVandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this for a while, and it looks good. We can revert if something pops up

@nx-cloud
Copy link

nx-cloud bot commented Feb 28, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit b4ea6f3. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createColumnHelper loses typesafety when TData contains only optional fields

2 participants