Microsoft/TypeScript

Unexpected declaration error when using symbols and intersections

Open

#59,541 建立於 2024年8月6日

在 GitHub 查看
 (1 留言) (2 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: Declaration EmitHelp Wanted

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

🔎 Search Terms

  • declarations

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about generating declarations.

⏯ Playground Link

https://www.typescriptlang.org/dev/bug-workbench/?#code/PTAEAEDMEsBsFMB2BDAtvAXKWB7A5nvAE4B0ALgM4BQ8AHgA45FmgDGOiFLAMvoUQFUASgElQAXlABlAJ6oARjlgAKAES8CxVQEoA3FRoMmLMjPrxQG-lOIA3aKwuSA3qEg4cWLkWiI8oAF9QADJQZypQUABtK2JhEQBdLFd5ZCIvMh8-QP0A-SoQCBgEFHQsZHpocmpoVEZmUAAqUGQKSz5iNyIcVFBVEmBcTSJVfLp6lgATeFZYNIt2ThZIRAB1LAAeAEEAGlAAIQA+ZWQsLe0JQ9BleSx9i-ErrZCD-XHjUGnZ+bYOLjdEJstsdTqBzpdrrcwQ8nvkvnMiAs-ixaFhYqR0TYiPZHPlCoAZckAfBuAel2CmAAKJGZjwSagWxpaDIeQIUAAcmQrNAAAtWqAmKBoG0AK4UXz+UoWVno+KcyDdXp0MjEFCwUCoHCTIUs1TFTAgQYdEageRClisZCIRA4FjyCwSyYkZQAFgADAAmADM2kME1+SxaEgBq2UtD0ZNAgFByH0fRb-eSBlYhsNAA

💻 Code

// @filename: logger.ts
export const LoggerURI = Symbol("Logger");

export type LoggerService = { foo: string } & {
  [LoggerURI]: { bar: string };
};

// @filename: api.ts
import * as Logger from "./logger";

export declare const fnW: <A, B>(a: A) => (b: B) => A & B;
export declare const fn: <A>(a: A) => (b: A) => A;

declare const x: Logger.LoggerService;

// ❌🤯
// Exported variable 'a' has or is using name 'LoggerURI' from external module "file:///logger" but cannot be named.(4023)
export const a = fnW(x);
// ✅
export const b = fn(x);

🙁 Actual behavior

Unexpected type error:

Exported variable 'a' has or is using name 'LoggerURI' from external module "file:///logger" but cannot be named.(4023)

🙂 Expected behavior

No type error. LoggerURI is exported so it can be named.

Additional information about the issue

No response

貢獻者指南