Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug: [consistent-type-export] Declaration shadowing causes false positive #11388

Open
Labels
accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@Xunnamius

Description

@Xunnamius

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I havesearched for related issues and found none that matched my issue.
  • I haveread the FAQ and my problem is not listed.

Issue Description

Take theError class. As far as I can tell, TypeScript differentiates between theruntime nameError, which is anErrorConstructor that you callnew on, versus thetype nameError, which is what is returned by theErrorConstructor in the type system:

consterror:Error=newError()

Where the nameError is simultaneously the TypeScript type and the runtime object.

Suppose I want to decorate subclasses ofError on the fly:

/* eslint-disable @typescript-eslint/no-explicit-any */functiondecorateErrorClass<Textendsnew(...args:any[])=>Error>(errorConstructor:T){constdecoratedConstructor=errorConstructorasT&{additionalStaticProp:boolean;};decoratedConstructor.additionalStaticProp=true;return{MyError:decoratedConstructor};}const{ MyError}=decorateErrorClass(classMyErrorextendsError{panic(){console.log('panicking!');}});/** * Some commentary that should be exported. */exporttypeMyError=InstanceType<typeofMyError>;// AFAICT if we don't export the instance type of MyError (above), DX degrades for importersexport{MyError};// MyError (class) and myError (instance) are both correctly typed in this file.constmyError=newMyError();console.log(MyError.additionalStaticProp);// truemyError.panic();// outputs: "panicking!"

And then, in some other file, I attempt to import and exportMyError:

import{MyError}from'./index.js';exporttypeSomethingElse=boolean;export{MyError};

npx eslint gives the following error:

npx eslint                              /tmp/tmp.1UuL6fdCYx/src/1-broken/bad.ts  5:1  error  All exportsin the declaration are only used as types. Use`export type`  @typescript-eslint/consistent-type-exports✖ 1 problem (1 error, 0 warnings)  1 error and 0 warnings potentially fixable with the`--fix` option.

What makes this false positive particularly pernicious is if I'm blindly applying--fix on the file I'm editing (as I am wont to do), it'll turn thatMyError runtime export into a type-only export. This breaks downstream consumers at runtime but the linter shows no issues.

My best guess: the issue is with the self-described "hack" online 154. I'd dig further, but the workaround in my case is easy and elegant enough:

- const { MyError } = decorateErrorClass(+ export const { MyError } = decorateErrorClass(  class MyError extends Error {    panic() {      console.log('panicking!');    }  });/** * Some commentary that should be exported. */export type MyError = InstanceType<typeof MyError>;- export { MyError };

Maybe related to#10313.

Reproduction Repository Link

https://github.com/Xunnamius/typescript-eslint-bug-repro-11388

Repro Steps

  1. clone the repo
  2. npm install
  3. npx eslint

Versions

packageversion
typescript-eslint8.36.0
@eslint/js9.30.1
TypeScript5.8.3
ESLint9.30.1
node22.17.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp