sveltekittsconfig.json

Is there a way for me to configure the "include" paths that get generated in SvelteKit's tsconfig.json?


My file structure is:

- src
- foo
  - script.ts
- tsconfig.json
- .svelte-kit
  - tsconfig.json
    ...

My goal is to have typescript files in /foo to be treated essentially as if they were in /src (I want to use types from src in /foo/*.ts). Modifying /.svelte-kit/tsconfig.json directly and adding "../foo/**/*.ts" to the include array gets me exactly what I want, however it will be discarded any time SvelteKit regenerates. Adding include paths in /tsconfig.json will overwrite those set in /.svelte-kit/tsconfig.json and break type checking, since apparently there's no way to append includes or excludes in nested tsconfigs.

I tried to look for a svelte or vite config option to accomplish this, but no luck. Anyone have any suggestions?


Solution

  • There is a function that can be specified in svelte.config.js for adjusting the generated config or replacing it:

    {
      kit: {
        adapter: adapter(),
        typescript: {
          config: cfg => {
            cfg.include.push('../foo/**/*.ts');
          },
        },
      },
    }