Microsoft/TypeScript
GitHub ã§èŠãunique symbol + interface + mixin causes TS4058 ("but cannot be named")
Open
#57,165 opened on 2024幎1æ25æ¥
BugDomain: Declaration EmitHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
"unique symbol", "interface", "computed property", "mixin", "TS4058"
ð Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Common "Bugs" That Aren't Bugs
⯠Playground Link
No response
ð» Code
// @filename: interface.ts
export const someUniqueSymbol = Symbol.for("some-unique-symbol");
export interface ISomeInterface {
[someUniqueSymbol]: string;
}
// @filename: class.ts
import { someUniqueSymbol, ISomeInterface } from "./interface";
export class SomeClass implements ISomeInterface {
[someUniqueSymbol] = "some-value";
}
// @filename: mixin.ts
import { SomeClass } from "./class";
type Constructor<T> = abstract new (...args: any[]) => T;
// An error occurs here:
// Return type of exported function has or is using name 'someUniqueSymbol'
// from external module "file:///class" but cannot be named.(4058)
export function SomeMixin<T extends Constructor<SomeClass>>(base: T) {
abstract class SomeMixin extends base {}
return SomeMixin;
}
ð Actual behavior
The compiler emits an error at the definition of function SomeMixin(), saying:
Return type of exported function has or is using name 'someUniqueSymbol'
from external module "file:///class" but cannot be named.(4058)
The problem disappears if you change the definition of someUniqueSymbol to:
export const someUniqueSymbol = "some-string";
I believe this is wrong for 3 reasons:
- There should be no reason why the type of
someUniqueSymbolcannot be named because it's exported byinterface.ts. - The message is wrong. It's from
interface.tsbut notclass.ts. - The function
SomeMixin()does not mentionsomeUniqueSymbol, or anything frominterface.tsat all, so it would be wrong to emit the error at the definition site of the said function.
ð Expected behavior
Compiles with no errors.
Additional information about the issue
This is similar to #37888 but I'm not sure if it's the same issue.