Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-bears-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/table-core': patch
---

Preserve `undefined` in deep accessor value types when an optional parent key is used.
2 changes: 1 addition & 1 deletion packages/table-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"clean": "rimraf ./build",
"test:lib": "vitest",
"test:lib:dev": "pnpm test:lib --watch",
"test:types": "tsc --noEmit",
"test:types": "tsc --noEmit && tsc --noEmit -p tsconfig.test-d.json",
"build": "pnpm build:rollup && pnpm build:types",
"build:rollup": "rollup --config rollup.config.mjs",
"build:types": "tsc --emitDeclarationOnly"
Expand Down
5 changes: 3 additions & 2 deletions packages/table-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ type DeepKeysPrefix<
? `${TPrefix}.${DeepKeys<T[TPrefix], [...TDepth, any]> & string}`
: never

export type DeepValue<T, TProp> =
T extends Record<string | number, any>
export type DeepValue<T, TProp> = T extends null | undefined
? undefined
: T extends Record<string | number, any>
? TProp extends `${infer TBranch}.${infer TDeepProp}`
? DeepValue<T[TBranch], TDeepProp>
: T[TProp & string]
Expand Down
27 changes: 27 additions & 0 deletions packages/table-core/tests/columnHelper.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createColumnHelper } from '../src'

type Expect<T extends true> = T
type Equal<T, U> =
(<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2
? true
: false

type Row = {
user: {
salary?: {
amount: number
}
}
}

const columnHelper = createColumnHelper<Row>()

columnHelper.accessor('user.salary.amount', {
cell: (info) => {
const amount = info.getValue()

type _ = Expect<Equal<typeof amount, number | undefined>>

return amount
},
})
8 changes: 8 additions & 0 deletions packages/table-core/tsconfig.test-d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"rootDir": "."
},
"include": ["src/**/*", "tests/**/*.test-d.ts"]
}