-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TS 3.7 generates inline imports for typing files (.d.ts) although the source contains imports at the top #36097
Comments
The difference to #30258 is that in that defect the inline import referred to a deduced type that had not been imported explicitly. The recommendation was This is exactly what's happening in this example, the type |
We encountered this issue in mui/material-ui-pickers#1465. The general gist is that import { createStyles } from '@material-ui/core';
export const styles = createStyles(); where The issue is that The correct declaration should be |
In OP's example, TypeScript has three options:
The first option has the problem that we could potentially introduce name conflicts, or need to do some name mangling to make sure existing other meanings of The second option is always safe. The third option is terrible and people hate it when we do this 🙂 You can add an import of |
@RyanCavanaugh I am not following this train of thought. The TS in question contains:
I would expect this type to be used in the typings file. There is no need to add a new import as mentioned in (1) nor to reference So I would prefer the fourth option, the TS compiler should use the type declaration as it was in the source (unless I am missing a point here). |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
Did you solve this? Any workarounds? |
This is a follow up to #30258. I am now using TS 3.7.4 and the compiler sometimes generates inline imports although the TS source contains imports in the head area of the file.
Example:
TS Source is:
After compilation the generated
.d.ts
file is:Many (but not all) of the import statements have been inlined.
Why is this happening and how can I avoid this?
The underlying problem is that I am using
@microsoft/api-extractor
and@microsoft/api-documenter
to generate documentation for my project. These tools rely on the information in the.d.ts
files to generate their doc and with the inline imports this end-user facing documentation becomes very hard to read, if not unusable.TypeScript Version: 3.7.4
Expected behavior:
I expect the import statements in the
.d.ts
files to match the import statements in thets
source.Actual behavior:
Imports are sometimes inlined, sometimes not. I cannot tell what causes the imports to be inlined.
Related Issues:
#30258
The text was updated successfully, but these errors were encountered: