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

Table2.focusMode: FocusMode enum unusable due to being re-exported as a type #7265

Open
Irfy opened this issue Feb 18, 2025 · 0 comments
Open

Comments

@Irfy
Copy link

Irfy commented Feb 18, 2025

Using the focusMode property of Table2 has issues.

  • Trying to use the enum <Table2 focusMode={FocusMode.ROW} /> results in:

error TS1362: 'FocusMode' cannot be used as a value because it was exported using 'export type'.

197 focusMode={FocusMode.ROW}
~~~~~~~~~

node_modules/@blueprintjs/table/lib/esm/common/index.d.ts:1:56
1 export type { CellCoordinates, FocusedCellCoordinates, FocusMode } from "./cellTypes";
~~~~~~~~~
'FocusMode' was exported here.

  • Trying to use the literal value assigned to FocusMode.ROW:

error TS2322: Type '"row"' is not assignable to type 'FocusMode | undefined'.

197 focusMode="row"
~~~~~~~~~

  • Using "row" as FocusMode works, but it defeats the typing engine and allows any value to be passed in. For example, focusMode={"foobar" as FocusMode} compiles just fine.

Environment

  • @blueprintjs/core: 5.16.6
  • @blueprintjs/table: 5.3.5
  • @blueprintjs/table: 5.3.5
  • typescript: 5.7.3

Possible solution

The FocusMode export chain looks like this:

  • defined in and exported as a value from @blueprintjs/table/lib/esm/common/cellTypes.d.ts
  • re-exported as a type from @blueprintjs/table/lib/esm/common/index.d.ts`
  • re-exported as a type from @blueprintjs/table/lib/esm/index.d.ts

I believe that the re-exports as a type are an oversight and re-exporting the enum as a value fixes the problem and allows the usage as focusMode={FocusMode.ROW}.

Tested by patching the installed files:

  • node_modules/@blueprintjs/table/lib/esm/common/index.d.ts: remove "type" in export
  • node_modules/@blueprintjs/table/lib/esm/common/index.js: add a new export for FocusMode
  • node_modules/@blueprintjs/table/lib/esm/index.d.ts: remove "type" in export
  • node_modules/@blueprintjs/table/lib/esm/index.js: add a new export for FocusMode
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

No branches or pull requests

1 participant