fix(web): fix typing for Parser.init

Since we're usually only providing `locateFile`, we need the type to be
`Partial<>` to allow it.

This also matches the typing in `@types/emscripten`'s
`EmscriptenModuleFactory` type signature.
This commit is contained in:
Tamir Bahar 2025-06-15 12:41:21 +03:00 committed by GitHub
parent 02fff92b91
commit 64760ffa76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 3 deletions

View file

@ -217,4 +217,4 @@ interface WasmModule {
}
export type MainModule = WasmModule & typeof RuntimeExports;
export default function MainModuleFactory (options?: EmscriptenModule): Promise<MainModule>;
export default function MainModuleFactory(options?: Partial<EmscriptenModule>): Promise<MainModule>;

View file

@ -9,7 +9,7 @@ export let Module: MainModule | null = null;
*
* Initialize the Tree-sitter WASM module. This should only be called by the {@link Parser} class via {@link Parser.init}.
*/
export async function initializeBinding(moduleOptions?: EmscriptenModule): Promise<MainModule> {
export async function initializeBinding(moduleOptions?: Partial<EmscriptenModule>): Promise<MainModule> {
if (!Module) {
Module = await createModule(moduleOptions);
}

View file

@ -105,7 +105,7 @@ export class Parser {
* You can optionally pass in options to configure the WASM module, the most common
* one being `locateFile` to help the module find the `.wasm` file.
*/
static async init(moduleOptions?: EmscriptenModule) {
static async init(moduleOptions?: Partial<EmscriptenModule>) {
setModule(await initializeBinding(moduleOptions));
TRANSFER_BUFFER = C._ts_init();
LANGUAGE_VERSION = C.getValue(TRANSFER_BUFFER, 'i32');