shared TS code between referenced projects

Viewed 108

I have generated a TS project with vite. That created two typescript config files: tsconfig.json and tsconfig.node.json. The relevant parts look like so:

// tsconfig.json
{
  …
  "include": ["src"],
  "references": [{ "path": "./tsconfig.node.json" }],
  …
}

// tsconfig.node.json
// I have added "./src/util/env.api.ts" to included,
// the only change
{
  "include": ["vite.config.ts", "./src/vite-env.d.ts", "./src/util/env.api.ts"]
}

In order to use the code from ./src/util/env.api.ts within build and the application I have added the file to the include list of tsconfig.node.ts as shown above.

BUT I now run npx tsc I get this error:

error TS6305: Output file '[…]/src/util/env.api.d.ts' has not been built from source file '[…]/src/util/env.api.ts'.
  The file is in the program because:
    Matched by include pattern 'src' in '[…]/tsconfig.json'

  tsconfig.json:19:15
    19   "include": ["src"],
                     ~~~~~
    File is matched by include pattern specified here.


Found 1 error.

Without the change I am getting this one:

File '[…]/src/util/env.api.ts' is not listed within the file list of project '[…]/tsconfig.node.json'. Projects must list all files or use an 'include' pattern.

So, either way around there is some kind of error. How can I share code between those two TS projects?

0 Answers
Related