Hello, I’m integrating Svelte into my Meteor project. I’m using the svelte:compiler and svelte packages. On the backend I’m using Typescript, the native Meteor version.
I’d like to take advantage of Typescript on the frontend too. Now Svelte just has included Typescript support as well. How do I do this? Does anyone know if there is an update underway of svelte:compiler and do I even need this?
No. I think you have to use svelte - preprocessor and use that to compile typescript in svelte. Since that is done before svelte gets compiled itself, I don’t think there should be an issue with Meteor. I abandoned Typescript. It does away with all the Javascript advantages. For Meteor the refactoring is a pain. I figured I didn’t need schemas anymore for MongoDB, which is not true. I hate simple schema, but TS doesn’t take its place. I use check / Match now. Works well. Good luck!
By now, yes. You have to use zodern:melte, svelte-preprocess, typescript through npm, to allow compiling Svelte script tags (), as well as typescript with Meteor (meteor add typescript). Key is to have the right versions of everything. Typescript with Meteor is 4.4.1, but I can’t find a normal one of this on npm, so I use 4.4.2. I’m also using Svelte 3.29.7. Found that one by trial and error.
Funny, every time I search for the combination of svelte, meteor and typescript I stumble upon my own post.
I had to spend another day trialling and erroring the most updated versions that work together. I now use:
npm modules:
svelte: 3.46.4
svelte-preprocess: 5.0.0
tinro: 0.6.12
typescript front end: 4.9.4
You can certainly use the newest svelte version. When I have some spare time, I want to publish a working guide. There is just one issue left and that is broken sourcemaps and eg console.logs refer to incorrect code.
Also, the atmospehere typescript seems to be working better than the npm version. I am yet to investigate because it seems to be a bit inconsistent.
Use the zodern:types package, that helps a lot with importing. There is a bug in 2.9.0 that breaks it for some modules though.
Also, the tsconfig needs to be correctly set. This seems to be my minimal setup:
{
// see https://guide.meteor.com/build-tool.html#typescript for a config example
"compilerOptions": {
"allowSyntheticDefaultImports": true, // to be able to import eg meteor/mongo
"baseUrl": ".", // required by "paths"
"module": "esNext", // required by "preserveValueImports"
"moduleResolution": "node", // required by zodern:types (not documented)
"paths": {
"/*": ["*"], // support absolute /imports/* with a leading '/'
// support Meteor/Atmospehere packages, required by zodern:types
"meteor/*": [
"node_modules/@types/meteor/*",
".meteor/local/types/packages.d.ts"
]
},
"preserveSymlinks": true, // required by zodern:types
"preserveValueImports": true, // otherwise TS will remove imported components
"types": ["node", "svelte"]
},
"exclude": ["./.meteor/**", "./packages/**"] // this may solve VS Code Svelte plugin warnings
}
Hello, I’m integrating Svelte into my Meteor project. I’m using the svelte:compiler and svelte packages. On the backend I’m using Typescript, the native Meteor version.
I’d like to take advantage of Typescript on the frontend too. Now Svelte just has included Typescript support as well. How do I do this? Does anyone know if there is an update underway of svelte:compiler and do I even need this?