Skip to content

Enum used as object key is not exported in declaration #35329

@hcomnetworkers

Description

@hcomnetworkers

TypeScript Version: 3.8.0-dev.20191125 (@next), but was present in 3.4 already

Search Terms:

  • typescript ts4023
  • Exported variable has or is using name from external module but cannot be named
  • typescript enum declaration

Code

Selectors.ts

import {State} from './Store';
export const pageUiSelector = (state: State) => state.ui;

Store.ts

export enum Pages {
  dashboard = 'dashboard',
}
export interface State {
  ui: {
    [Pages.dashboard]: {
      selectedRow: number | null;
    };
  };
}

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "declaration": true,
    "module": "commonjs",
    "rootDir": ".",
    "strict": true,
    "target": "es2017"
  }
}

Expected behavior:
No error.

Actual behavior:
This error is thrown:

Selectors.ts:2:14 - error TS4023: Exported variable 'pageUiSelector' has or is using name 'Pages' from external module "xxx/Store" but cannot be named.

Details:
This error only occurs when exporting the given selector and when using --declaration. The probable cause is that the enum values used as object key is not properly detected and added to the exported files.

If the enum is not used as object key, but as object value, the error does not occur.
If the content of Store.ts is moved to Selectors.ts, the error does not occur.

This code works as expected in the ts-loader via webpack, however tsc and PhpStorm report this as error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts files

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions