Skip to content

Generate types from spark-rs for Packed-/ExtSplatsResult - #508

Open
mrxz wants to merge 1 commit into
sparkjsdev:mainfrom
mrxz:wasm-ts-types
Open

mrxz wants to merge 1 commit into
sparkjsdev:mainfrom
mrxz:wasm-ts-types

Conversation

@mrxz

@mrxz mrxz commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Refactor so that the spark-rs wasm project generates proper TypeScript types, which in turn are used by the worker. Motivation for this change comes from trying to add support for the extra and comment fields of SOGv3. Since these will have to be parsed by spark-lib and passed through spark-rs -> worker -> Packed/ExtSplats it's important each conversion happens safely. Without proper type information this becomes a lot more error-prone and maintenance heavy.

The old flow had the following steps:

  • spark-rs generated a JS object dynamically for either PackedSplats or ExtSplats
  • spark_rs.d.ts declared these as any
  • worker.ts casts these to either DecodedPackedResult/DecodedExtResult
  • worker.ts converts from DecodedPackedResult/DecodedExtResult to a shared PackedResult/ExtResult (in defines.ts)
  • Callers of the worker made use of the fact that PackedResult/ExtResult are compatible with PackedSplatsOptions/ExtSplatsOptions

This PR introduces the PackedSplatsResult and ExtSplatsResult structs in Rust, annotated using tsify, so that it generates proper types. These have been structured in such a way that the conversion in worker.ts is no longer needed, resulting in the following steps:

  • spark-rs creates an instance of PackedSplatsResult/ExtSplatsResult
  • spark_rs.d.ts has proper TypeScript types for these
  • worker.ts can simply return these to the caller
  • Callers of the worker make use of the fact that the new PackedSplatsResult/ExtSplatsResult are compatible with PackedSplatsOptions/ExtSplatsOptions

For further type safety, the ChunkDecoder is made generic (on the TypeScript side). This allows a decoder.finish() in worker.ts to have a proper type, instead of any as well.

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.

1 participant