microsoft / microsoft/TypeScript

Symbol = LiveSymbol | DeadSymbol

Open
#59,574 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔍 Search Terms

symbol weakmap TC39

✅ Viability Checklist
⭐ Suggestion

The latest version of ES creates a new kind of runtime error. It allows symbols to be used as weak map keys, but only some symbols. In particular it splits the symbol primitive in two. One one hand are "live" symbols, tracked by the garbage collector, and usable as weak map keys. Symbol() creates a live symbol. On the other had are "dead" symbols, such as Symbol.iterator, which return some value from Symbol.keyFor(sym) and are not legal keys for weak maps.

Since there are now fundamentally two incompatible primitive types, TS should adjust so that it is capable of catching these errors again.

📃 Motivating Example
const protos = new WeakMap();

const sym = Math.random() > 0.5 ? Symbol() : Symbol.for('me');

protos.set(sym, null); // crashes half the time
💻 Use Cases

Catching more errors

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the motivating WeakMap example and the ECMAScript rules distinguishing live and dead symbols. Trace how TypeScript represents symbols and checks WeakMap keys, then determine the type-system changes and tests needed so invalid dead-symbol keys are rejected without changing emitted JavaScript.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers, devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.