svelte-preprocess
svelte-preprocess copied to clipboard
Add an ability to set a custom typescript compiler
Is your feature request related to a problem? Please describe.
There is this amazing module that lets you type check your data in runtime called typescript-is. It is super useful especially for data that comes from a third party (like an API). The module relies on a custom typescript compiler ttypescript, which is not supported by svelte-preprocess
.
Describe the solution you'd like
I would like to have a config option (like typescript: {implementation: require('ttypescript') }
). The same way you currently have an option to set sass implementation https://github.com/sveltejs/svelte-preprocess/issues/148.
Describe alternatives you've considered
Right now the only way you can use ttypescript with Svelte is by using a rollup plugin in vite.config.js
:
import { sveltekit } from "@sveltejs/kit/vite";
import loader from "rollup-plugin-typescript2";
import typescript from "ttypescript";
const transformer = { ...loader({ typescript }), enforce: "pre" };
/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit(), transformer],
};
export default config;
BUT! That would work only for .ts
files and not .svelte
files!
How important is this feature to you? That would be great to have a native support for that. Right now I'm actively looking for workaround (no luck so far)... Runtime type checking is essential to my project. So, this is a blocking factor for me at the moment. I appreciate any solutions you might suggest, no matter how hacky they are.
Additional context
typescript-is docs mention that transpileOnly
mode will break the library. So, it would be great to also have an option to configure that. If I understand correctly since v4
, svelte-preprocess
doesn't type-check, which might break typescript-is
(I guess). If so, an option to enable type checking back would be appreciated.
that workaround doesn't work for me
error when starting dev server:
TypeError: Cannot read properties of undefined (reading 'options')
at Context.resolveId (C:\project\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:28064:93)
at Object.resolveId (file:///C:/project/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:40156:46)
at async ModuleGraph.resolveUrl (file:///C:/project/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:60507:26)
at async ModuleGraph.ensureEntryFromUrl (file:///C:/project/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:60455:41)
at async instantiateModule (file:///C:/project/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:52964:17)