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

Typescript: Sheet cells almost always gets typed as any #13

Open
PooSham opened this issue Oct 21, 2022 · 0 comments
Open

Typescript: Sheet cells almost always gets typed as any #13

PooSham opened this issue Oct 21, 2022 · 0 comments

Comments

@PooSham
Copy link

PooSham commented Oct 21, 2022

Due to this type definition:

[cell: string]: CellObject | SheetKeys | any;

In the Sheet interface (and similar type definition in the WorkSheet interface), we always get the type any unless we use one of the "special keys". The CellObject | SheetKeys part is actually of no use for the developer, since it gets evaluated to any when any is added to the type union.

any is usually considered something to be avoided in typescript, so it would probably be better to use unknown if there really is a need to support more than the types already defined. However, this would need to be accompanied with type predicates for CellObject, all SheetKeys types as well as all WSKeys types. That would allow typescript users to easily feel confident about the cell type they're working with.

I can create a PR for this if it's of any interest. It would be a breaking change for typescript users though, since they would get static type errors if they accessed a cell without asserting or type guarding themselves.

Maybe there are other solutions, such as creating different get-methods depending on if it's a CellObject or something else, but I think this is the simplest solution.

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