microsoft / microsoft/TypeScript
Symbol = LiveSymbol | DeadSymbol
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔍 Search Terms
symbol weakmap TC39
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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