opral / inlang-paraglide-js

Tree-shakable i18n library build on the inlang ecosystem.
https://inlang.com/m/gerre34r/library-inlang-paraglideJs
52 stars 1 forks source link

Generate TypeScript files instead of JS files? #238

Open sbking opened 1 month ago

sbking commented 1 month ago

I can not enable allowJs for my application because other build tooling (Remix + Vite) does not work well when allowJs is enabled. Is there any way to make Paraglide generate .ts files instead?

samuelstroschein commented 1 month ago

We can likely offer an option emitWithTsExtension

Can you test if changing the file endings to .ts works seamlessly in your project? Due to the JSDoc annotations, I expect TypeScript to work out of the box. If that's the case, then we don't have to use the typescript compiler which we tried to avoid to keep the complexity low

sbking commented 1 month ago

Unfortunately no, looks like JSDoc type annotations are only supported in JS files.

That said, I think my actual problem was that I was missing Remix's unstable_optimizeDeps flag and I think allowJs is now working fine. I think I would still prefer an option to generate .ts files to align with the rest of my codebase, but for now it's less of an issue.

samuelstroschein commented 1 month ago

Can confirm. TypeScript complains with "ts 80004: Please convert JSDoc to TypeScript types".

Ergh bummer. It seems like we need to run the typescript compiler with emitDeclarations only to parse the JSDoc and emit d.ts files https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html.

Good news: We won't need an option because we can emit both .js and .d.ts files. JS projects shouldn't be affected.

@sbking are you open for a PR against the lix-integration branch that has paraglide js 2.0? Then we can include this in the paraglide js 2.0 release

EDIT: If parallel .js (jsdoc) and .d.ts files works, then we can also get rid of the entire allowJs step in the setup. That's great!