GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support ES6 built-in symbols by JsonFreeman · Pull Request #1978 · microsoft/TypeScript

Conversation

@JsonFreeman

@JsonFreeman Jason Freeman (JsonFreeman) commented Feb 7, 2015

Copy link
Copy Markdown
Contributor

This change adds type checking support for properties whose names are the built-in ES symbols. It allows you to create objects like:

var obj = {
    [Symbol.toStringTag]() {
        return "";
    }
}

And you get the right type when you index:

obj[Symbol.toStringTag](0); // Error because the method expected no arguments

I've also added a new keyword for the symbol primitive type, as well as type guard support, errors for all the operators ,etc. To see the full design discussion, see #980.

This pull request fixes #1750, and #1863. However, strong type information is only available for the built-in ES6 symbols (properties of the global Symbol object).

This does not cover symbol indexers, which allows an object to act as a map with arbitrary symbol keys.

I also did my best to allow symbol polyfilling to work on the type side, provided that the provider of the polyfill also provide the typings for the global Symbol object.

I recommend going through the pull request commit-by-commit, although some commits were experiments that were largely reverted later on. This is mainly true for the following two commits, so feel free to skip them if you like:

  • Allow Symbol indexer in ES6
  • Create global Symbol type

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

SlurpTheo reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Jason Freeman (JsonFreeman) added 30 commits February 6, 2015 21:31
@JsonFreeman
Allow Symbol indexer in ES6
11d75ef
@JsonFreeman
Change computed property error messages to be about symbols
b30d8f3
@JsonFreeman
Syntactically allow computed properties everywhere if the name looks …
39952b1
…like a built in Symbol
@JsonFreeman
Move hasDynamicName to utilities.ts
d788624
@JsonFreeman
Update hasDynamicName to take well known symbols into account
07f3641
@JsonFreeman
Add named property symbol for known Symbol properties
f344654
@JsonFreeman
Change computed property error message to mention Symbols
30892af
@JsonFreeman
Create global Symbol type
9cb38fb
@JsonFreeman
Change certain hasDynamicName checks to check the SyntaxKind instead
25fcbe2
@JsonFreeman
Add tests for operators with symbol operand
b60fa14
@JsonFreeman
Add tests for symbol properties
779661c
@JsonFreeman
Accept correct baselines for symbol property tests
95af997
@JsonFreeman
Add symbol keyword
e508bf7
@JsonFreeman
Update tests to use new symbol keyword
ebdd96b
@JsonFreeman
Change isTypeOfKind calls to pass symbol TypeFlag when needed
e346b70
@JsonFreeman
Rename references in es6.d.ts from Symbol to symbol
59a704e
@JsonFreeman
Change Symbol to symbol in error messages
d793658
@JsonFreeman
Fix expression checking for symbols
2d16474
@JsonFreeman
Fix error message wording
6a6c03b
@JsonFreeman
Don't pass prop.name directly for error reporting
92617f5
@JsonFreeman
Add test for new Symbol()
fbeadbc
@JsonFreeman
Make Symbol the apparent type of symbol
9f39a53
@JsonFreeman
symbols in type guards
df826de
@JsonFreeman
Support indexing with known symbols
d07ed67
@JsonFreeman
Fix error message
8325862
@JsonFreeman
Refactor part of getPropertyNameForIndexedAccess into checkSymbolName…
3834edd
…IsProperSymbolReference
@JsonFreeman
Check that Symbol properties are proper, and support downlevel type c…
4c09ccd
…hecking
@JsonFreeman
Declaration emit for symbol properties
3560442
@JsonFreeman
Navigation bar support for symbols
2f3c32a
@JsonFreeman
Disable symbol indexer
eb50619
@JsonFreeman
Accept baselines after rebase
75382c1
@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-not-required label Feb 7, 2015
@JsonFreeman Jason Freeman (JsonFreeman) mentioned this pull request Feb 9, 2015
Allow indexing with symbols #1863
Closed
@JsonFreeman Jason Freeman (JsonFreeman) removed the cla-not-required label Feb 9, 2015
Jason Freeman (JsonFreeman) referenced this pull request Feb 10, 2015
@DanielRosenwasser
Emit computed properties in ES3/ES5 properly.
ddb63d2
Jason Freeman (JsonFreeman) added 3 commits February 10, 2015 16:13
@JsonFreeman
Address feedback from @yuit
18276e5
@JsonFreeman
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
a94e61b
… esSymbols

Conflicts:
	src/compiler/diagnosticInformationMap.generated.ts
@JsonFreeman
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
486cebd
… esSymbols
DanielRosenwasser
DanielRosenwasser reviewed Feb 12, 2015
View reviewed changes
Comment thread src/compiler/checker.ts Outdated

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Feb 12, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before Otherwise

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Jason Freeman (JsonFreeman) added 6 commits February 12, 2015 17:36
@JsonFreeman
Address feedback
4942c5f
@JsonFreeman
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
9c273d8
… esSymbols

Conflicts:
	src/services/services.ts
@JsonFreeman
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
65d831e
… esSymbols
@JsonFreeman
Error for naming an interface 'symbol'
ac829a8
@JsonFreeman
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
7d7d54f
… esSymbols

Conflicts:
	src/compiler/diagnosticInformationMap.generated.ts
	src/compiler/diagnosticMessages.json
@JsonFreeman
Rebaseline after merge
935c602
DanielRosenwasser
DanielRosenwasser reviewed Feb 17, 2015
View reviewed changes
Comment thread src/compiler/checker.ts Outdated

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Feb 17, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

someTypeHasKind

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@JsonFreeman
Address feedback
59dc7d3
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Feb 17, 2015

Copy link
Copy Markdown
Member

👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Jason Freeman (JsonFreeman) added 2 commits February 17, 2015 12:39
@JsonFreeman
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
dd6a129
… esSymbols
@JsonFreeman
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
47404bc
… esSymbols
Jason Freeman (JsonFreeman) added a commit that referenced this pull request Feb 18, 2015
@JsonFreeman
Merge pull request #1978 from Microsoft/esSymbols
aa13a97
Support ES6 built-in symbols
@JsonFreeman
Jason Freeman (JsonFreeman) merged commit aa13a97 into master Feb 18, 2015
@JsonFreeman
Jason Freeman (JsonFreeman) deleted the esSymbols branch February 18, 2015 21:19
@Vadorequest

Vadorequest (Vadorequest) commented Feb 28, 2015

Copy link
Copy Markdown

👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Symbols should not be allowed as operands of arithmetic operations.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@JsonFreeman @DanielRosenwasser @Vadorequest @yuit @msftclas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.