salomonbrys
08/13/2024, 12:57 PMES2015 modules :
• The per-file mode generates one .d.ts declaration file per Kotlin file, but thoses .d.ts files are not linked between them. For example, one .d.ts file declares the getUser(): User; function, and another declares the export declare class User . That's because they are in different Kotlin files (in fact they even are in different modules). This makes it impossible for our TypeScript devs to use correctly since they are missing a lot of type information.
• The default per-module mode generates one big .d.ts file which contains all modules definitions (Which feels weird, I expected one .d.ts per module). Each module is still compiled in its own .mjs file. Let's say I have a test project with two modules: export and lib . In this example, Kotlin will generate the test-export.mjs, test-export.d.ts and test-lib.mjs files. The test-export.d.ts file will contain both modules definitions (which fixes the declaration dependency issue) but now there is no way for our TypeScript devs to import declarations in the lib module with their corresponding TS definitions (since they are compiled in test-lib.mjs but declared in test-export.d.ts.
• The whole-program mode generates a single big .mjs file, accompanied by its .d.ts declaration file, which fixes both issues, but this feels like a missed opportunity to properly use ES2015 and segment code properly. Also, the types key is not defined in package.json, so it needs to be added manually (this is true for all modes).
So far, only the whole-program mode seems to allow us to export to TS multiple symbols from multiple Kotlin modules. Is there something I am missing ?turansky
08/13/2024, 2:39 PMwhole-program - best solutionturansky
08/13/2024, 2:40 PMbut this feels like a missed opportunity to properly use ES2015 and segment code properlyLooks like terser responsibility 😉
turansky
08/13/2024, 2:43 PMimport { A, B, C, D } from "my-kjs-lib"
// or
import { A } from "my-kjs-lib/A"
import { B } from "my-kjs-lib/B"
import { C } from "my-kjs-lib/C"
import { D } from "my-kjs-lib/D"
In case of Kotlin/JS first variant will produce more compact bundle 😉turansky
08/13/2024, 2:44 PMturansky
08/13/2024, 2:44 PMsalomonbrys
08/13/2024, 3:01 PMper-module or per-file ?turansky
08/13/2024, 3:05 PMindex.mjs and index.d.ts - best API from user perspective
2. Additional initialization guardes inside files
3. File rename in Kotlin -> new import for user 😞CLOVIS
08/13/2024, 3:11 PMper-file would be faster in development, since less of the bundle needs to be regenerated?turansky
08/13/2024, 3:22 PMper-file would be faster in development, since less of the bundle needs to be regenerated?
I also expect such behaviour.
But it looks like KJS application problem (not library).