# Disable Symbol and symbol keyed properties (`ts-compat/no-symbol`) 💼 This rule is enabled in the ✅ `recommended` config. Symbol cannot be perfectly polyfilled. Using it in older browsers comes with the following costs: every time a Symbol is created, a property is added to the prototype of Object; there is no guarantee that Symbol properties are non-enumerable. This rule prohibits creating custom Symbols, calling `Symbol.for`, and using custom Symbols as property keys, but it does not restrict the well-known Symbols such as `Symbol.iterator` or `Symbol.toStringTag`, because they are part of the language protocol and a shim can not provide them anyway. `Symbol` needs Chrome 40, Edge 12, Firefox 36, Safari 9, Opera 27 or iOS Safari 9 to run and it has never been supported by any version of IE. `Symbol.for` needs the same versions. When a custom Symbol is only there to hide a property, use a private class field (`#name`). ## Rule Details Examples of **incorrect** code for this rule: ```ts var s = Symbol(); var t = Symbol("description"); var u = Symbol.for("key"); var o: any = {}; o[s] = 1; o[t] += 1; Object.defineProperty(o, u, { value: 1 }); ``` Examples of **correct** code for this rule: ```ts class Foo { [Symbol.hasInstance]() { return true; } } var o: Record = {}; o.x = 1; o["x"] = 1; function tag(target: object) { Object.defineProperty(target, Symbol.toStringTag, { value: "Foo" }); } tag(new Foo()); var iterable: any = {}; iterable[Symbol.iterator] = function () { }; iterable[Symbol.isConcatSpreadable] = true; class Counter { #count = 0; increase() { this.#count++; return this.#count; } } const counter = new Counter(); counter.increase(); ``` ## When Not To Use It * Every target browser supports `Symbol`. * Using Symbol in the architecture layer and considering unsupported scenarios. ## Further Reading * [Private properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties) * [MDN Symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)