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

Can't access any internal types #11240

Open
jonahallibone opened this issue Oct 29, 2024 · 4 comments
Open

Can't access any internal types #11240

jonahallibone opened this issue Oct 29, 2024 · 4 comments

Comments

@jonahallibone
Copy link

jonahallibone commented Oct 29, 2024

Describe the bug

I am unable to type my component properly as I cannot import CellMeta, GridSettings etc from react or base libraries.

This is how I've resorted to accessing the types:

import type HandsonTypes from "handsontable/base";
...
type CellMeta = HandsonTypes.CellMeta;

I would be great to be able to import import type { CellMeta } from "handsontable/base" or "handsontable" directly

Video/Screenshots

No response

Provide a link to the demo with the bug reproduction

No response

Handsontable version

14.6.1

Framework version

No response

Your environment

MacOS

@adrianszymanski89
Copy link
Contributor

Hi @jonahallibone

Thank you for the suggestions. We are constantly improving the types definitions. I will report this idea internally and update you once I have any updates.

@jonahallibone
Copy link
Author

Hi @jonahallibone

Thank you for the suggestions. We are constantly improving the types definitions. I will report this idea internally and update you once I have any updates.

Great! For a more detail example, take this function I have written below:

const getCells: HandsonTypes.GridSettings["cells"] = (...props) => {
    const [x, y] = props;

    if (data?.[x]?.[y]) {
      const isReadOnly = data[x][y].editable === false;

      return {
        readOnly: isReadOnly,
      };
    }

    return {};
  };

  const memData = useMemo(
    () => data.map((row) => row.map((cell) => cell.value)),
    []
  );

I see from the type defs you're exporting the entire namespace, and i'm unsure if there's a way to export the types without the namespace as a flat object, but I think it would be a much nicer experience.

Accessing the cells prop type via HandsonTypes.GridSettings["cells"] isn't ideal for a couple reasons:

Firstly, aesthetics. It's not a huge deal, but needing to import the namespace, then dot-access the object I want to use followed by needing to index on that object to retrieve the property type is sort of unintuitive, and frankly doesn't look super nice. I could remap them all to named types at the top of my file, but at that point I'd hope the library would export them as such.

Secondly, intellisense. I had no way of knowing how to access these types with clicking through 3 files of type definitions and hoping that my import would work. Generally, if a type is used in the type definition of function or object, I'd expect it to be available as a direct import from the library.

As an example:
Screenshot 2024-10-29 at 12 04 30 PM

in this screenshot we have GridSettings.cells, CellMeta, and CellProperties required to make a typesafe callback for the cells props, but unless you want to inline your callback, you'd need to more or less go search around teh .d.ts files for those types and import them yourself, which makes typesafe callbacks sort of tedious to work with and visually busy.

Anyway, I'm enjoying Handsontable and I understand how type exporting is always something each org has a different opinion on. I just wanted to highlight a couple ways I think the experience of using Handsontable could be made more seamless and simple.

@alamchrstn
Copy link

just wanted to upvote this. I have a project that uses internal type(s) from pluginHooks and settings quite extensively. But since we're moving on with having a stricter TS compiler options, these become unavailable. Maybe we can extend the exports in handsontable's package.json to include these files?

"exports": {
    // ... rest of the exports
    "./pluginHooks": {
      "types": "./pluginHooks.d.ts",
      "require": "./pluginHooks.js",
      "import": "./pluginHooks.mjs"
    }
}

@adrianszymanski89
Copy link
Contributor

@jonahallibone @alamchrstn

Thank you for your input. We really appreciate it. I have already added this enhancement to our internal board and will update you as soon as I have any news on the topic.

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

No branches or pull requests

3 participants