From 08d3a63caf80751f033291bf5c439cdefa218ca1 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 24 Oct 2024 10:46:17 +0200 Subject: [PATCH] NFC Python: Tidy up some typescript types (#2985) I removed some ts-ignores --- src/pyodide/internal/snapshot.ts | 14 ++++++-------- src/pyodide/types/FS.d.ts | 2 +- src/pyodide/types/artifacts.d.ts | 11 ++++++++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/pyodide/internal/snapshot.ts b/src/pyodide/internal/snapshot.ts index 1841008ad12..08868bc8525 100644 --- a/src/pyodide/internal/snapshot.ts +++ b/src/pyodide/internal/snapshot.ts @@ -185,7 +185,6 @@ function recordDsoHandles(Module: Module): DylinkInfo { // whose importer is not FrozenImporter or BuiltinImporter. // const SNAPSHOT_IMPORTS: string[] = - // @ts-ignore getSnapshotImports is a static method. ArtifactBundler.constructor.getSnapshotImports(); /** @@ -206,7 +205,7 @@ const SNAPSHOT_IMPORTS: string[] = * * This function returns a list of modules that have been imported. */ -function memorySnapshotDoImports(Module: Module): Array { +function memorySnapshotDoImports(Module: Module): string[] { const toImport = SNAPSHOT_IMPORTS.join(','); const toDelete = Array.from( new Set(SNAPSHOT_IMPORTS.map((x) => x.split('.', 1)[0])) @@ -230,13 +229,12 @@ function memorySnapshotDoImports(Module: Module): Array { // The `importedModules` list will contain all modules that have been imported, including local // modules, the usual `js` and other stdlib modules. We want to filter out local imports, so we // grab them and put them into a set for fast filtering. - const importedModules: Array = - // @ts-ignore filterPythonScriptImportsJs is a static method. + const importedModules: string[] = ArtifactBundler.constructor.filterPythonScriptImportsJs( MetadataReader.getNames(), - ArtifactBundler.constructor - // @ts-ignore parsePythonScriptImports is a static method. - .parsePythonScriptImports(MetadataReader.getWorkerFiles('py')) + ArtifactBundler.constructor.parsePythonScriptImports( + MetadataReader.getWorkerFiles('py') + ) ); const deduplicatedModules = [...new Set(importedModules)]; @@ -285,7 +283,7 @@ function makeLinearMemorySnapshot( function setUploadFunction( snapshot: Uint8Array, - importedModulesList: Array + importedModulesList: string[] ): void { if (snapshot.constructor.name !== 'Uint8Array') { throw new TypeError('Expected TO_UPLOAD to be a Uint8Array'); diff --git a/src/pyodide/types/FS.d.ts b/src/pyodide/types/FS.d.ts index 30e6b005b3b..edbc9f4e48f 100644 --- a/src/pyodide/types/FS.d.ts +++ b/src/pyodide/types/FS.d.ts @@ -29,7 +29,7 @@ interface FS { mode: number ): FSNode; isFile: (mode: number) => boolean; - readdir: (path: string) => Array; + readdir: (path: string) => string[]; genericErrors: Error[]; } diff --git a/src/pyodide/types/artifacts.d.ts b/src/pyodide/types/artifacts.d.ts index 8a1957e716c..81dbcff4ea4 100644 --- a/src/pyodide/types/artifacts.d.ts +++ b/src/pyodide/types/artifacts.d.ts @@ -1,7 +1,16 @@ declare namespace ArtifactBundler { + const constructor: { + getSnapshotImports(): string[]; + filterPythonScriptImportsJs( + fileNames: string[], + imports: string[] + ): string[]; + parsePythonScriptImports(fileNames: string[]): string[]; + }; + type MemorySnapshotResult = { snapshot: Uint8Array; - importedModulesList: Array; + importedModulesList: string[]; }; const hasMemorySnapshot: () => boolean;