Closed
Description
Bug Report
π Search Terms
preProcessFile, ts.preProcessFile
, template literal types
π Version & Regression Information
- This is the behavior in every version I tried (tried v4.1.5, v4.5.4 and nightly).
β― Playground Link
Playground link with relevant code
π» Code
/*
THIS IS CORRECTLY IGNORED
```
import * as react from 'react';
```
*/
type Foo = `${string}`;
/**
THIS IS NOT IGNORED
```
import {Get} from 'type-fest';
import * as lodash from 'lodash';
```
*/
Or, as a quick node example:
> ts.preProcessFile(`\
... type Foo = \`\${string}\`;
... /**
... \`\`\`
... import {Get} from 'type-fest';
... import * as lodash from 'lodash';
... \`\`\`
... */
... `)
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: 'type-fest', pos: 50, end: 59 },
{ fileName: 'lodash', pos: 87, end: 93 }
],
isLibFile: false,
ambientExternalModules: undefined
}
π Actual behavior
ts.preProcessFile
parses the import
s within comments after the template literal type.
π Expected behavior
The import
s within the comment are ignored correctly after the template literal type.
Might be related to #30878?
Original report: microsoft/TypeScript-Website#2243
This causes issues with the TS playground because it will over-fetch types based on the pre-process result. This can cause startup delays, esp with packages like lodash
which have a huge numbers of files to fetch.