-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Description
Describe the bug
When TData type passed to createColumnHelper has all fields optional, we lose type-safety when using columnHelper.accessor function.
All fields are infering types just fine, but we lose this sanity check and this column becomes ColumnDef<Person, unknown>.
Marking any field as required (lifting ? from at least one field e.g. firstName: string;) will bring back expected error.
Not sure if that's a bug or a feature, but we actually spend some time before noticing typo.
Your minimal, reproducible example
Codesandbox forked Basic example
Steps to reproduce
- Fork Basic example
- Make all fields of
Personoptional:
type Person = {
firstName?: string;
lastName?: string;
age?: number;
visits?: number;
status?: string;
progress?: number;
};
- Use not existing key of Person:
const columnHelper = createColumnHelper<Person>();
const columns = [
columnHelper.accessor("definitely-not-a-person-key", { // This doesn't throw any ts errors
cell: (info) => info.getValue(),
footer: (info) => info.column.id,
}),
...
Expected behavior
Expected line 52. to throw ts error
Argument of type '"definitely-not-a-person-key"' is not assignable to parameter of type 'AccessorFn<Person> | "firstName" | "lastName" | "age" | "visits" | "status" | "progress"'
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Platform doesn't matter - ts issue
react-table version
^8.11.3
TypeScript version
No response
Additional context
No response
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels