Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error on computed name class member #61510

Open
Andarist opened this issue Mar 31, 2025 · 2 comments
Open

Confusing error on computed name class member #61510

Andarist opened this issue Mar 31, 2025 · 2 comments
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@Andarist
Copy link
Contributor

πŸ”Ž Search Terms

late bindable computed symbol class member

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?target=99&lib=lib.esnext.d.ts&ts=5.9.0-dev.20250326#code/MYewdgzgLgBArmAlgRzgUwMoE8C2AjEAGwAYYBeGbfIgOgDMQAnACgCJWBKAbgCge6EwKInAwA5migBVJKky4CJZhwBcMKFgAOaEHXiz0VRaQDePGDEaS4jMPpSGFRYrwC+fYIQCGECDADChBAAzDBmFgDaEtIG8tRKHAC65DCsdIiM0KxuPEA

πŸ’» Code

const uniqueSymbol0 = Symbol.for("");

function getUniqueSymbol0(): typeof uniqueSymbol0 {
  return uniqueSymbol0;
}

class Cls3 {
  [getUniqueSymbol0()] = "first"; // A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type.(1166)
}

πŸ™ Actual behavior

The error is confusing because this expression has a unique symbol type already

πŸ™‚ Expected behavior

This error should mention more accurate late-bindable requirements. From the source code:

    /**
     * Indicates whether a declaration name is definitely late-bindable.
     * A declaration name is only late-bindable if:
     * - It is a `ComputedPropertyName`.
     * - Its expression is an `Identifier` or either a `PropertyAccessExpression` an
     * `ElementAccessExpression` consisting only of these same three types of nodes.
     * - The type of its expression is a string or numeric literal type, or is a `unique symbol` type.
     */

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Mar 31, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 31, 2025
@Arya-A-Nair
Copy link

@RyanCavanaugh would like to work on this issue

@MartinJohns
Copy link
Contributor

would like to work on this issue

@Arya-A-Nair Please read: https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md#issue-claiming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

No branches or pull requests

4 participants