Skip to content

TS 3.7 generates inline imports for typing files (.d.ts) although the source contains imports at the top  #36097

@CarstenLeue

Description

@CarstenLeue

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:

import {
  AbstractRegisteredComponent,
  AbstractRegisteredLayoutMapping
} from '@acoustic-content-sdk/component-utils';
import { ComponentTypeRef } from '@acoustic-content-sdk/react-api';

import { LayoutComponentDirective } from './layout.directive';

export type RegisteredComponent = AbstractRegisteredComponent<
  ComponentTypeRef,
  LayoutComponentDirective
>;

export type RegisteredLayoutMapping = AbstractRegisteredLayoutMapping<
  ComponentTypeRef
>;

const KEY_COMPONENT = Symbol();
const KEY_LAYOUT_MAPPING = Symbol();

export const registerComponent = (
  aType: ComponentTypeRef,
  aRegistration: RegisteredComponent
) => (aType[KEY_COMPONENT] = aRegistration);

export const registerLayoutMapping = (
  aType: ComponentTypeRef,
  aRegistration: RegisteredLayoutMapping
) => (aType[KEY_LAYOUT_MAPPING] = aRegistration);

export const getRegisteredComponent = (
  aType: ComponentTypeRef
): RegisteredComponent => aType[KEY_COMPONENT];

After compilation the generated .d.ts file is:

import { AbstractRegisteredComponent, AbstractRegisteredLayoutMapping } from '@acoustic-content-sdk/component-utils';
import { ComponentTypeRef } from '@acoustic-content-sdk/react-api';
import { LayoutComponentDirective } from './layout.directive';
export declare type RegisteredComponent = AbstractRegisteredComponent<ComponentTypeRef, LayoutComponentDirective>;
export declare type RegisteredLayoutMapping = AbstractRegisteredLayoutMapping<ComponentTypeRef>;
export declare const registerComponent: (aType: import("@acoustic-content-sdk/react-api").ReactComponent<import("@acoustic-content-sdk/react-api").ReactComponentProps, any>, aRegistration: RegisteredComponent) => RegisteredComponent;
export declare const registerLayoutMapping: (aType: import("@acoustic-content-sdk/react-api").ReactComponent<import("@acoustic-content-sdk/react-api").ReactComponentProps, any>, aRegistration: RegisteredLayoutMapping) => RegisteredLayoutMapping;
export declare const getRegisteredComponent: (aType: import("@acoustic-content-sdk/react-api").ReactComponent<import("@acoustic-content-sdk/react-api").ReactComponentProps, any>) => RegisteredComponent;

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 the ts source.

Actual behavior:

Imports are sometimes inlined, sometimes not. I cannot tell what causes the imports to be inlined.

Related Issues:

#30258

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions