Skip to content

TS looses track of enum coming from module declaration #61744

Closed as not planned
Closed as not planned
@ernestostifano

Description

@ernestostifano

πŸ”Ž Search Terms

"module declaration enum issue", "module declaration enum any"

πŸ•— Version & Regression Information

Difficult to test in previous version because multi-file setup is required for reproduction.

⏯ Playground Link

https://github.com/ernestostifano/typescript-eslint-issue-1

πŸ’» Code

Issue Description

./src/common.types.ts

enum EMyEnum {
    Value = 'value'
}

export {EMyEnum};

./src/utilities.ts

import {EMyEnum} from './common.types.js';

function internalFunction(arg: EMyEnum | null): void {
    console.log(arg);
}

export {internalFunction};

./src/modules.d.ts

declare module 'my-module' {
    import {EMyEnum} from './common.types.js';

    function externalFunction(arg: EMyEnum | null): void;

    export {externalFunction};
}

./src/index.ts

import {externalFunction} from 'my-module';
import {internalFunction} from './utilities.js';

// INCORRECT: TS DOES NOT HIGHLIGHT THE ERROR
externalFunction('TEST');

// CORRECT: TS HIGHLIGHTS ERROR BECAUSE THE ARGUMENT MUST BE AN ENUM
internalFunction('TEST');

Reproduction Repository Link

https://github.com/ernestostifano/typescript-eslint-issue-1

Repro Steps

  1. Clone the repo.
  2. See README.md.

πŸ™ Actual behavior

See above.

πŸ™‚ Expected behavior

See above.

Additional information about the issue

Versions

package version
TypeScript 5.8.3
node 22.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions