Search code examples
sveltesveltekit

Svelte, JavaScript and JSDoc?


As far as I know, Svelte is written in JavaScript with JSDoc.

I'd like to learn Svelte and prefer to use JSDoc. When initialising a project with npm create svelte@latest, I'm asked the following:

◆  Add type checking with TypeScript?
│  ● Yes, using JavaScript with JSDoc comments
│  ○ Yes, using TypeScript syntax
│  ○ No
└

My first instict was to select Yes, using JavaScript with JSDoc comments, but then I saw the question was Add type checking with TypeScript?

What does JavaScript with JSDoc have to do with TypeScript? Why does Svelte offer this weird combination of TypeScript with JavaScript and JSDoc?

And would I have to select No, when I want to use pure JavaScript with JSDoc?


Solution

  • If you choose "Yes, using JavaScript with JSDoc comments" it will set up:

    • A jsconfig.json which configures TypeScript to check JS files ("strict", "allowJs", "checkJs", etc.).
    • Scripts and dependencies in package.json which can be used to check components.
      Type errors in components do not cause builds to fail. You can use the scripts check or check:watch to ensure type safety in component code.

    If you select "No" you just get the default checks provided by whatever IDE/extensions you are using.