Skip to content

Confusing error on computed name class memberΒ #61510

@Andarist

Description

@Andarist

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Error MessagesThe issue relates to error messagingHelp WantedYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions