EDIT 2020-07-24: Svelte now officially supports TypeScript
It only takes a few steps to use TypeScript in your .svelte files within <script ...
For further actions, you may consider blocking this person and/or reporting abuse
Thank you for the tutorial Markus!
I tried to use it, but it gives the error below:
Error: Cannot find module 'C:\sapper-with-ts-sample_sapper_\dev\server\server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Function.executeUserEntryPoint as runMain
at internal/main/run_main_module.js:18:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
Any ideas?
Make sure you have
and not
for the server
(I had the same error after copy/paste)
You might want to do a
npm install
or
Same here!
Is it possible to move the
hello
variable declaration to another typescript file?I tried putting this in
src/hello.ts
:But importing from
index.svelte
:Produces an error:
But it works fine if I don't use
.ts
file ...You can create a
src/components/hello.ts
fileAnd import it in
src/routes/index.svelte
withOr in
src/components/hello.ts
:with in
src/routes/index.svelte
:What you can do if you want to write your TypeScript code to an extra file:
Add this to your
index.svelte
:And in your
src/hello.ts
:Hi Markus,
It did not work for me. I keep getting:
Do you have a github repo I can clone demonstrating how to use typescript with svelte?
The default template repo now provides a script that helps you to convert the project to Typescript.
Just clone the template project
and run
node scripts/setupTypeScriptRollup.js
For me it was
setupTypeScript.js
You did had to go and make honor to your namesake* :D
Thanks for this little how-to!
*(Häcker without the umlaut-)