typescript icon indicating copy to clipboard operation
typescript copied to clipboard

Declaration files emitted doesn't include all the imports

Open pavandv opened this issue 2 years ago • 0 comments

The declaration files emitted from the ts.createProgram doesn't include all the imported modules from the source file.

For ex:

// useConfig.ts

import {InitialConfig} from './initialConfig';

export const useConfig = () => {
  const [config, setConfig] = useState<InitialConfig>();

  const updateConfig = (data: InitialConfig) => {
    setConfig(data);
  }

  return {
    config,
    updateConfig,
  }
};

The declaration file generated from compilation file is as follows:

// useConfig.d.ts

export declare const useConfig: () => {
  config: unknown;
  updateConfig: (data: InitialConfig) => void;
}

ts.createProgram is not including InitialConfig as part of the generated .d.ts file, and as such we can't be able to use any types generated.

pavandv avatar Aug 29 '22 18:08 pavandv