镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

unique symbol lost on assignment to const despite type assertion  #55901

Description

🔎 Search Terms

unique symbol widening

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground Link

💻 Code

const u = Symbol();
const a7 = u as typeof u // widened  to symbol

🙁 Actual behavior

a7 is symbol

🙂 Expected behavior

a7 has typeof u

Additional information about the issue

This issue is a huge problem for isolated declarations as it breaks the assumption that in an expression const o = a as T we can always use T as the type of o. This is also inconsistent with the way similar expressions work for string/number literal types (ex)

Similar issues:

Mateusz Burzyński (@Andarist) perhaps #54778 also fixes this?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions