Skip to content

Commit

Permalink
fix: type-check included files missed by transform (type-only files)
Browse files Browse the repository at this point in the history
- type-only files never get processed by Rollup as their imports are
  elided/removed by TS in the resulting compiled JS file
  - so, as a workaround, make sure that all files in the `tsconfig`
    `include` (i.e. in `parsedConfig.fileNames`) are also type-checked
    - note that this will not catch _all_ type-only imports, in
      particular if one is using `tsconfig` `files` (or in general _not_
      using glob patterns in `include`) -- this is just a workaround,
      that requires a separate fix
  - we do the same process for generating declarations for "missed"
    files right now in `_onwrite`, so basically do the same thing but
    for type-checking in `_ongenerate`

(_technically_ speaking, there could be full TS files
(i.e. _not_ type-only) that are in the `include` and weren't
transformed
- these would basically be independent TS files not part of the bundle
  that the user wanted type-checking and declarations for (as we
  _already_ generate declarations for those files))
  • Loading branch information
agilgur5 committed Jun 5, 2022
1 parent 8b5016b commit aeb11a7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,23 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
});
}

// type-check missed files as well
parsedConfig.fileNames.forEach((name) =>
{
if (!pluginOptions.check)
return;

const key = normalize(name);
if (key in declarations || !filter(key)) // don't duplicate if it's already been transformed
return;

context.debug(() => `type-checking missed '${key}'`);

const snapshot = servicesHost.getScriptSnapshot(key);
if (snapshot)
typecheckFile(key, snapshot, context);
});

if (!watchMode && !noErrors)
context.info(yellow("there were errors or warnings."));

Expand Down

0 comments on commit aeb11a7

Please sign in to comment.