Skip to content

Stricter typing across the library - #77

Merged
lazarusA merged 8 commits into
mainfrom
stricter-types
Nov 9, 2026
Merged

lazarusA merged 8 commits into
mainfrom
stricter-types

Conversation

@Karinon

@Karinon Karinon commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Mostly a typing cleanup. Behaviour should stay the same except for the fixes listed below. This is the first iteration of stricter types. The goal is to replace all occurrences of any in the end. This is not really a breaking change, but one could argue it is, as some of the types are now enforced.

Changes

  • Dependencies: updated dev dependencies (cpx2, rimraf) and added @types/emscripten. The hand-written any types for the Emscripten module and FS are replaced with the official types.
  • Error handling: new toError() helper in errors.ts, with tests. All catch (err: any) blocks now use unknown plus toError().
  • Shared types: AnyTypedArray moved into types.ts and replaces the long typed-array unions it duplicated.
  • Stricter constants and modes:
    • NC_CONSTANTS is now as const.
    • New FILE_MODES table, with derived FileMode / OpenMode / CreateMode types.
    • mode in Dataset() and the from* factories, including the public wrappers in index.ts, is now FileMode instead of string.
    • Worker messages are typed.
  • Cleanup: removed duplicate NC_LONGLONG / NC_ULONGLONG entries from the getter maps. They are aliases of NC_INT64 / NC_UINT64 and only became visible as errors after as const.

Fixes found along the way

  • Attribute and group-name lengths read as 64-bit values are now converted to number. Emscripten returns them as BigInt, which the old types hid.
  • open() handles the worker path and the regular read path in one branch. Creating files works as before.

Notes

  • TYPE_NAMES is commented out, since nothing used it.

@lazarusA

lazarusA commented Nov 4, 2026

Copy link
Copy Markdown
Member

pretty much in favour of deleting code (but some could remain as placeholders in the meantime, only if, needed and planned).

Is this good to go?

Comment thread src/constants.ts Resolved
Comment thread src/types.ts Resolved
@Karinon

Karinon commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

pretty much in favour of deleting code (but some could remain as placeholders in the meantime, only if, needed and planned).

Is this good to go?

From my point of view this is good to go. As mentioned I am going to create more PRs to get rid of the remaining anys, but I want to keep the size of the PRs reasonable.

@lazarusA
lazarusA merged commit 868e8fd into main Nov 9, 2026
2 checks passed
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

Successfully merging this pull request may close these issues.

3 participants