Reputation: 199
I've been using the template referenced in this Svelte blog article to start learning about Typescript.
The app is building and serving fine. But I have some code like this:
<script lang="ts">
let isDone: boolean = false;
isDone = 'somestring'
console.log(isDone)
</script>
I'm just starting out in Typescript, but shouldn't this be invalid? I'm not seeing any errors during npm run build
or npm run serve
. I don't use VS - is that where you'd expect this to be picked up?
Upvotes: 1
Views: 306
Reputation: 5436
npm run build
executes the build pipeline, which includes preprocessing the TypeScript contents inside Svelte files to JavaScript. This is a transpile-only process, because it happens on a per-file-basis. This means type checking during build would be incomplete/wrong. That's why there's a dedicated package called svelte-check
, which does the type checking. It's included in the setupTypeScript.js
-script of the template and can be invoked with npm run validate
. There's also a watch mode for svelte-check
if you'd like to run that alongside npm run dev
. npm Link with a README on all the options: https://www.npmjs.com/package/svelte-check
Upvotes: 2