Cast required to access custom options when defining a custom plugin/feature
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- react, typescript
調査の方向性
Start with packages/table-core/src/types/TableFeatures.ts and compare its published types with the custom-plugin example and custom features guide. Reproduce the TypeScript errors in the linked example, then determine how custom feature options should be exposed without casts or whether the documentation must be corrected. Done means the intended custom-plugin usage type-checks consistently and the guide matches the supported API.
索引モデルが issue の本文から書いたものです。
説明
TanStack Table version
9.2.4
Framework/Library version
Vue 3.5.43
Describe the bug and the steps to reproduce it
When defining a custom plugin/feature, a cast is required to access any options that it adds. For example, this is can be observed in an official example for custom plugins--on lines 108 and 119, table.options requires a cast to access onDensityChange. Here's the relevant code for convenience:
constructTableAPIs: (table) => {
assignTableAPIs('densityPlugin', table, {
table_setDensity: {
fn: (updater: Updater<DensityState>) => {
const safeUpdater: Updater<DensityState> = (old) => {
const newState = functionalUpdate(updater, old)
return newState
}
return (table.options as TableOptions_Density).onDensityChange?.(
safeUpdater,
)
},
},
table_toggleDensity: {
fn: (value?: DensityState) => {
const safeUpdater: Updater<DensityState> = (old) => {
if (value) return value
return old === 'lg' ? 'md' : old === 'md' ? 'sm' : 'lg' // cycle through the 3 options
}
return (table.options as TableOptions_Density).onDensityChange?.(
safeUpdater,
)
},
},
})
},
In theory, the internal Table_Internal type used in the TableFeature definition should be able to load options added by plugins, but this type is stripped from the published code (I guess using the code from this PR?), so the type exposed to custom plugin authors is the regular Table, which does not come with plugins by default. Interestingly, Table has support for Table<any, any> to load all plugins, but trying to set that on the table in the constructTableAPIs function causes its own type error since that doesn't match the type set by TableFeature.
export const densityPlugin: TableFeature = {
constructTableAPIs: (table: Table<any, any>) => {
// can now access table.options.onDensityChange with the correct types, but now this function itself causes a type error:
/*
Type
<TFeatures extends TableFeatures, TData extends RowData>(table: Table<any, any>) => void
is not assignable to type
<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>) => void
*/
}
}
I'm not sure what the best way to solve this is; I see a few possibilities:
- leave it as is; a couple type casts isn't a huge deal.
- in this case, the docs should be updated--e.g., the custom features guide says "If the TypeScript types are set up correctly, you should have no TypeScript errors when you create the feature object with the new state, options, and instance APIs." but the example code immediately afterwards does not have the cast, so it actually does have TS errors.
- change TableFeature to use a different/new
Table_Alltype that actually gets published - change TableFeature to accept generic parameters for its own custom options/state/etc.? (not sure we'd have access to the right TFeatures/TData then, though, and I have no idea what that would do to typechecking performance.)
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
https://tanstack.com/table/latest/docs/framework/react/examples/custom-plugin
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
None
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
- 主要言語
- TypeScript
- スター
- 28.4k
- フォーク
- 3.6k
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 7
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/table のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 78/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
bug v2
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
modelcontextprotocol/inspector#2458 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
railmapgen/rmp-gallery#4068 ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
carbon-design-system/ibm-products#9907 ·